File tree Expand file tree Collapse file tree 1 file changed +9
-10
lines changed
Expand file tree Collapse file tree 1 file changed +9
-10
lines changed Original file line number Diff line number Diff line change 33package org .bson .util ;
44
55import java .util .*;
6+ import java .util .concurrent .*;
67
78public 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}
You can’t perform that action at this time.
0 commit comments