aboutsummaryrefslogtreecommitdiff
path: root/other/java/client/src
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2020-07-20 18:26:48 -0700
committerChris Lu <chris.lu@gmail.com>2020-07-20 18:26:48 -0700
commitcacc601cc8dd8c6cae8a5d03921a5966306b909e (patch)
treeb2f95516bff599af0c90a78bda158b1691b02917 /other/java/client/src
parentaee6d893506020fe327642b1f7a106a2f0bd7fd1 (diff)
downloadseaweedfs-cacc601cc8dd8c6cae8a5d03921a5966306b909e.tar.xz
seaweedfs-cacc601cc8dd8c6cae8a5d03921a5966306b909e.zip
ensure changing buffer size requirements
Diffstat (limited to 'other/java/client/src')
-rw-r--r--other/java/client/src/main/java/seaweedfs/client/ByteBufferPool.java23
1 files changed, 20 insertions, 3 deletions
diff --git a/other/java/client/src/main/java/seaweedfs/client/ByteBufferPool.java b/other/java/client/src/main/java/seaweedfs/client/ByteBufferPool.java
index 897fe9694..55f003a18 100644
--- a/other/java/client/src/main/java/seaweedfs/client/ByteBufferPool.java
+++ b/other/java/client/src/main/java/seaweedfs/client/ByteBufferPool.java
@@ -1,22 +1,39 @@
package seaweedfs.client;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
public class ByteBufferPool {
- static List<ByteBuffer> bufferList = new ArrayList<>();
+ private static final int MIN_BUFFER_SIZE = 8 * 1024 * 1024;
+ private static final Logger LOG = LoggerFactory.getLogger(ByteBufferPool.class);
+
+ private static final List<ByteBuffer> bufferList = new ArrayList<>();
public static synchronized ByteBuffer request(int bufferSize) {
+ if (bufferSize < MIN_BUFFER_SIZE) {
+ bufferSize = MIN_BUFFER_SIZE;
+ }
if (bufferList.isEmpty()) {
return ByteBuffer.allocate(bufferSize);
}
- return bufferList.remove(bufferList.size()-1);
+ ByteBuffer buffer = bufferList.remove(bufferList.size() - 1);
+ if (buffer.capacity() >= bufferSize) {
+ return buffer;
+ }
+
+ LOG.info("add new buffer from {} to {}", buffer.capacity(), bufferSize);
+ bufferList.add(0, buffer);
+ return ByteBuffer.allocate(bufferSize);
+
}
public static synchronized void release(ByteBuffer obj) {
- bufferList.add(obj);
+ bufferList.add(0, obj);
}
}