Skip to content

Commit

Permalink
fix: concurrent problem in DecoderMap. #852
Browse files Browse the repository at this point in the history
  • Loading branch information
areyouok committed Jan 20, 2024
1 parent 795023f commit 7802a31
Showing 1 changed file with 11 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,19 @@ public AbstractValueDecoder getDecoder(int identityNumber) {
}

public void register(int identityNumber, AbstractValueDecoder decoder) {
reentrantLock.lock();
try {
decoderMap.put(identityNumber, decoder);
inited = true;
}finally {
reentrantLock.unlock();
}
decoderMap.put(identityNumber, decoder);
}

public void clear() {
reentrantLock.lock();
try {
decoderMap.clear();
inited = true;
}finally {
reentrantLock.unlock();
}
decoderMap.clear();
}

public ReentrantLock getLock() {
return reentrantLock;
}

public void setInited(boolean inited) {
this.inited = inited;
}

public void initDefaultDecoder() {
Expand All @@ -64,7 +60,7 @@ public void initDefaultDecoder() {
register(SerialPolicy.IDENTITY_NUMBER_KRYO5, Kryo5ValueDecoder.INSTANCE);
// register(SerialPolicy.IDENTITY_NUMBER_FASTJSON2, Fastjson2ValueDecoder.INSTANCE);
inited = true;
}finally {
} finally {
reentrantLock.unlock();
}
}
Expand Down

0 comments on commit 7802a31

Please sign in to comment.