Skip to content

Commit

Permalink
optimize: reduce unnecessary synchronized (apache#1799)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsbxyyx authored and zjinlei committed Oct 23, 2019
1 parent ab32bee commit 8c80c5c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions core/src/main/java/io/seata/core/codec/CodecFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ public class CodecFactory {
* @param codec the code
* @return the codec
*/
public static synchronized Codec getCodec(byte codec) {
public static Codec getCodec(byte codec) {
CodecType codecType = CodecType.getByCode(codec);
if (CODEC_MAP.get(codecType) != null) {
return CODEC_MAP.get(codecType);
}
Codec codecImpl = EnhancedServiceLoader.load(Codec.class, codecType.name());
CODEC_MAP.put(codecType, codecImpl);
CODEC_MAP.putIfAbsent(codecType, codecImpl);
return codecImpl;
}

Expand Down
6 changes: 3 additions & 3 deletions server/src/main/java/io/seata/server/lock/LockerFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class LockerFactory {
*
* @return the lock manager
*/
public static synchronized final LockManager getLockManager() {
public static final LockManager getLockManager() {
return lockManager;
}

Expand All @@ -77,7 +77,7 @@ public static synchronized final LockManager getLockManager() {
* @param branchSession the branch session
* @return the lock manager
*/
public static synchronized final Locker get(BranchSession branchSession) {
public static final Locker get(BranchSession branchSession) {
String storeMode = CONFIG.getConfig(ConfigurationKeys.STORE_MODE);
if (StoreMode.DB.name().equalsIgnoreCase(storeMode)) {
if (lockerMap.get(storeMode) != null) {
Expand All @@ -90,7 +90,7 @@ public static synchronized final Locker get(BranchSession branchSession) {
DataSource logStoreDataSource = dataSourceGenerator.generateDataSource();
locker = EnhancedServiceLoader.load(Locker.class, storeMode, new Class[] {DataSource.class},
new Object[] {logStoreDataSource});
lockerMap.put(storeMode, locker);
lockerMap.putIfAbsent(storeMode, locker);
} else if (StoreMode.FILE.name().equalsIgnoreCase(storeMode)) {
locker = EnhancedServiceLoader.load(Locker.class, storeMode,
new Class[] {BranchSession.class}, new Object[] {branchSession});
Expand Down

0 comments on commit 8c80c5c

Please sign in to comment.