Skip to content

Commit 8fd4c13

Browse files
committed
JAVA-613: Changing synchronized to volatile for integer only modified by one thread
1 parent 827ef20 commit 8fd4c13

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/main/com/mongodb/OutMessage.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,12 @@ String getNamespace() {
257257
return _collection != null ? _collection.getFullName() : null;
258258
}
259259

260-
synchronized int getNumDocuments() {
260+
int getNumDocuments() {
261261
return _numDocuments;
262262
}
263263

264264
@Override
265-
public synchronized int putObject(BSONObject o) {
265+
public int putObject(BSONObject o) {
266266
// check max size
267267
int objectSize = _encoder.writeObject(_buf, o);
268268
if (objectSize > Math.max(_mongo.getConnector().getMaxBsonObjectSize(), Bytes.MAX_OBJECT_SIZE)) {
@@ -280,5 +280,5 @@ public synchronized int putObject(BSONObject o) {
280280
private final int _queryOptions;
281281
private final DBObject _query;
282282
private final DBEncoder _encoder;
283-
private int _numDocuments;
283+
private volatile int _numDocuments; // only one thread will modify this field, so volatile is sufficient synchronization
284284
}

0 commit comments

Comments
 (0)