bytebufferpool.java

来自「一个实用工具类」· Java 代码 · 共 44 行

JAVA
44
字号
/* * Copyright (C) butor.com. All rights reserved. * * This software is published under the terms of the GNU Library General * Public License (GNU LGPL), a copy of which has been included with this * distribution in the LICENSE.txt file.  */package org.butor.socket.nio;import java.nio.ByteBuffer;import java.util.Stack;/* *TODO * * @author sawanai * @date Feb 14, 2006 */public class ByteBufferPool {	// pool of StringBuffer	protected static Stack stack = new Stack();		protected static ByteBuffer getStringBuffer() {		synchronized (stack) {			if (stack.size() > 0) {				ByteBuffer bb = (ByteBuffer) stack.pop();				return bb;			}		}		return ByteBuffer.allocate(512);	}	protected static void keepByteBuffer(ByteBuffer bb) {		synchronized (stack) {			if (stack.size() < 1000) { //keep 1000 maximum				bb.clear();				stack.push(bb);			}		}	}}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?