Skip to content

Commit dbb00be

Browse files
committed
close sockets on Mongo.close() - don't wait for gc
1 parent 18b1363 commit dbb00be

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/main/com/mongodb/DBPortPool.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ void close(){
169169
clear();
170170
}
171171

172+
public void cleanup( DBPort p ){
173+
p.close();
174+
}
175+
172176
public boolean ok( DBPort t ){
173177
return _addr.equals( t._addr );
174178
}

src/main/com/mongodb/util/SimplePool.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ public boolean ok( T t ){
6565
return true;
6666
}
6767

68+
/**
69+
* override this if you need to do any cleanup
70+
*/
71+
public void cleanup( T t ){}
72+
6873
/**
6974
* @return >= 0 the one to use, -1 don't use any
7075
*/
@@ -107,6 +112,9 @@ void done( T t , boolean ok ){
107112
_waiting.release();
108113
}
109114
}
115+
else {
116+
cleanup( t );
117+
}
110118
}
111119
}
112120

@@ -223,10 +231,14 @@ private void _wherePrint(){
223231

224232
/** Clears the pool of all objects. */
225233
protected void clear(){
226-
_avail.clear();
227-
_all.clear();
228-
synchronized ( _where ){
229-
_where.clear(); // is this correct
234+
synchronized( _avail ){
235+
for ( T t : _avail )
236+
cleanup( t );
237+
_avail.clear();
238+
_all.clear();
239+
synchronized ( _where ){
240+
_where.clear(); // is this correct
241+
}
230242
}
231243
}
232244

0 commit comments

Comments
 (0)