Skip to content

Commit 8a5a0ee

Browse files
committed
Boxing "bufferQueueTotalAmount" so that the Synchronization is done over it's internal semaphore, not the WebSocket instance one.
1 parent 527311c commit 8a5a0ee

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/org/java_websocket/WebSocket.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public enum Role {
9393
* The amount of bytes still in queue to be sent, at every given time.
9494
* It's updated at every send/sent operation.
9595
*/
96-
private long bufferQueueTotalAmount = 0;
96+
private Long bufferQueueTotalAmount = (long) 0;
9797

9898
private Draft draft = null;
9999

@@ -494,7 +494,7 @@ public void flush() throws IOException {
494494
if( buffer.remaining() > 0 ) {
495495
continue;
496496
} else {
497-
synchronized (this) {
497+
synchronized (bufferQueueTotalAmount) {
498498
// subtract this amount of data from the total queued (synchronized over this object)
499499
bufferQueueTotalAmount -= buffer.limit();
500500
}
@@ -545,7 +545,7 @@ private void channelWrite( ByteBuffer buf ) throws InterruptedException {
545545
if( DEBUG )
546546
System.out.println( "write(" + buf.limit() + "): {" + ( buf.limit() > 1000 ? "too big to display" : new String( buf.array() ) ) + "}" );
547547
buf.rewind();
548-
synchronized (this) {
548+
synchronized (bufferQueueTotalAmount) {
549549
// add up the number of bytes to the total queued (synchronized over this object)
550550
bufferQueueTotalAmount += buf.limit();
551551
}

0 commit comments

Comments
 (0)