From 4713091555d06367bacbca369a9e1882ccf6acfd Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Sat, 17 Apr 2010 16:45:50 +0000 Subject: [PATCH] Always reset direct buffer when reused. --- .../springframework/integration/ip/tcp/NioSocketWriter.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/org.springframework.integration.ip/src/main/java/org/springframework/integration/ip/tcp/NioSocketWriter.java b/org.springframework.integration.ip/src/main/java/org/springframework/integration/ip/tcp/NioSocketWriter.java index ceca448b79..b559c8d08e 100644 --- a/org.springframework.integration.ip/src/main/java/org/springframework/integration/ip/tcp/NioSocketWriter.java +++ b/org.springframework.integration.ip/src/main/java/org/springframework/integration/ip/tcp/NioSocketWriter.java @@ -102,6 +102,7 @@ public class NioSocketWriter extends AbstractSocketWriter { protected ByteBuffer getBuffer() throws InterruptedException { ByteBuffer buffer = this.buffers.poll(); if (buffer != null) { + buffer.clear(); return buffer; } synchronized (buffers) { @@ -109,11 +110,6 @@ public class NioSocketWriter extends AbstractSocketWriter { bufferCount++; return ByteBuffer.allocateDirect(this.sendBufferSize); } - // another thread may have returned one while we were sync'd - buffer = this.buffers.poll(); - if (buffer != null) { - return buffer; - } } buffer = this.buffers.take(); buffer.clear();