Skip to content

Commit 4338530

Browse files
committed
JAVA-236: make it possible to clean up ThreadLocal
1 parent d261f8a commit 4338530

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/main/com/mongodb/DBTCPConnector.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -455,11 +455,18 @@ public String debugString(){
455455

456456
public void close(){
457457
_closed = true;
458-
if ( _portHolder != null )
458+
if ( _portHolder != null ) {
459459
_portHolder.close();
460-
if ( _rsStatus != null )
460+
_portHolder = null;
461+
}
462+
if ( _rsStatus != null ) {
461463
_rsStatus.close();
462-
_myPort = null;
464+
_rsStatus = null;
465+
}
466+
467+
// below this will remove the myport for this thread only
468+
// client using thread pool in web framework may need to call close() from all threads
469+
_myPort.remove();
463470
}
464471

465472
/**
@@ -500,7 +507,7 @@ public int getMaxBsonObjectSize() {
500507
private DBPortPool _masterPortPool;
501508
private DBPortPool.Holder _portHolder;
502509
private final List<ServerAddress> _allHosts;
503-
private final ReplicaSetStatus _rsStatus;
510+
private ReplicaSetStatus _rsStatus;
504511
private boolean _closed = false;
505512
private int maxBsonObjectSize = 0;
506513

0 commit comments

Comments
 (0)