Skip to content

Commit

Permalink
feat: ThreadLocal 자원 해제 로직 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
JJ503 committed Oct 10, 2023
1 parent ea8fa73 commit 4595f7a
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.springframework.transaction.support;

import javax.annotation.Nullable;
import javax.sql.DataSource;
import java.sql.Connection;
import java.util.HashMap;
Expand All @@ -11,6 +12,7 @@ public abstract class TransactionSynchronizationManager {

private TransactionSynchronizationManager() {}

@Nullable
public static Connection getResource(DataSource key) {
final Map<DataSource, Connection> connectionHolder = resources.get();

Expand All @@ -32,13 +34,20 @@ public static void bindResource(DataSource key, Connection value) {
connectionHolder.put(key, value);
}

@Nullable
public static Connection unbindResource(DataSource key) {
final Map<DataSource, Connection> connectionHolder = resources.get();

if (connectionHolder == null) {
return null;
}

return connectionHolder.remove(key);
final Connection removeConnection = connectionHolder.remove(key);

if (connectionHolder.isEmpty()) {
resources.remove();
}

return removeConnection;
}
}

0 comments on commit 4595f7a

Please sign in to comment.