Skip to content

Commit

Permalink
feat: threadLocal 초기화 로직 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
youngh0 committed Oct 11, 2023
1 parent 5cdec8a commit d113ecf
Showing 1 changed file with 4 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,23 @@

public abstract class TransactionSynchronizationManager {

private static final ThreadLocal<Map<DataSource, Connection>> resources = new ThreadLocal<>();
private static final ThreadLocal<Map<DataSource, Connection>> resources = ThreadLocal.withInitial(HashMap::new);

private TransactionSynchronizationManager() {
}

public static Connection getResource(DataSource key) {
Map<DataSource, Connection> resource = resources.get();
if (resource == null) {
return null;
}
return resource.get(key);
}

public static void bindResource(DataSource key, Connection value) {
final Map<DataSource, Connection> connectionMap = new HashMap<>(Map.of(key, value));
resources.set(connectionMap);
Map<DataSource, Connection> currentResources = resources.get();
currentResources.put(key, value);
}

public static Connection unbindResource(DataSource key) {
Map<DataSource, Connection> resource = resources.get();
if (resource != null) {
return resource.remove(key);
}
return null;
return resource.remove(key);
}
}

0 comments on commit d113ecf

Please sign in to comment.