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();