Skip to content

Commit 525b786

Browse files
committed
use java.util.concurrent
1 parent 396cd57 commit 525b786

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/main/org/bson/util/SimplePool.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package org.bson.util;
44

55
import java.util.*;
6+
import java.util.concurrent.*;
67

78
public abstract class SimplePool<T> {
89

@@ -21,23 +22,21 @@ protected boolean ok( T t ){
2122
}
2223

2324
public T get(){
24-
synchronized ( _stored ){
25-
if ( _stored.size() > 0 )
26-
return _stored.removeFirst();
27-
}
25+
T t = _stored.poll();
26+
if ( t != null )
27+
return t;
2828
return createNew();
2929
}
3030

3131
public void done( T t ){
3232
if ( ! ok( t ) )
3333
return;
34-
synchronized ( _stored ){
35-
if ( _stored.size() > _max )
36-
return;
37-
_stored.addFirst( t );
38-
}
34+
35+
if ( _stored.size() > _max )
36+
return;
37+
_stored.add( t );
3938
}
4039

4140
final int _max;
42-
private LinkedList<T> _stored = new LinkedList<T>();
41+
private Queue<T> _stored = new ConcurrentLinkedQueue<T>();
4342
}

0 commit comments

Comments
 (0)