Skip to content

Commit 0cc187f

Browse files
committed
remove 1 ThreadLocal by putting BSONDecoder in DBPort JAVA-130
From hans
1 parent dca8c51 commit 0cc187f

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

src/main/com/mongodb/DBPort.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.*;
2424
import java.util.logging.*;
2525

26+
import org.bson.*;
2627
import com.mongodb.util.*;
2728

2829
public class DBPort {
@@ -93,7 +94,7 @@ private synchronized Response go( OutMessage msg , DBCollection coll )
9394
return null;
9495

9596
_processingResponse = true;
96-
return new Response( coll , _in );
97+
return new Response( coll , _in , _decoder);
9798
}
9899
catch ( IOException ioe ){
99100
close();
@@ -246,6 +247,7 @@ void checkAuth( DB db ){
246247
final DBPortPool _pool;
247248
final MongoOptions _options;
248249
final Logger _logger;
250+
final BSONDecoder _decoder = new BSONDecoder();
249251

250252
private Socket _socket;
251253
private InputStream _in;

src/main/com/mongodb/Response.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
class Response {
2828

29-
Response( DBCollection collection , InputStream in )
29+
Response( DBCollection collection , InputStream in, BSONDecoder decoder)
3030
throws IOException {
3131
_collection = collection;
3232

@@ -53,8 +53,7 @@ class Response {
5353
else
5454
_objects = new ArrayList<DBObject>( _num );
5555

56-
DBCallback c = DBCallback.FACTORY.create( _collection );
57-
BSONDecoder decoder = TL.get();
56+
DBCallback c = DBCallback.FACTORY.create( _collection );
5857

5958
for ( int i=0; i<_num; i++ ){
6059
if ( user._toGo < 5 )
@@ -182,9 +181,4 @@ public String toString(){
182181

183182
final List<DBObject> _objects;
184183

185-
static ThreadLocal<BSONDecoder> TL = new ThreadLocal<BSONDecoder>(){
186-
protected BSONDecoder initialValue(){
187-
return new BSONDecoder();
188-
}
189-
};
190184
}

0 commit comments

Comments
 (0)