本文整理汇总了Java中java.util.concurrent.ConcurrentLinkedQueue.offer方法的典型用法代码示例。如果您正苦于以下问题:Java ConcurrentLinkedQueue.offer方法的具体用法?Java ConcurrentLinkedQueue.offer怎么用?Java ConcurrentLinkedQueue.offer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.ConcurrentLinkedQueue
的用法示例。
在下文中一共展示了ConcurrentLinkedQueue.offer方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: returnArrayToPool
import java.util.concurrent.ConcurrentLinkedQueue; //导入方法依赖的package包/类
/**
* Recycles the specified byte array, so that future requests for a byte array of the same size may be fulfilled
* without allocating a new one.
*/
public static void returnArrayToPool(byte[] b)
{
ConcurrentLinkedQueue<byte[]> q = arrayPool.get(b.length);
if (q == null)
{
q = new ConcurrentLinkedQueue<byte[]>();
ConcurrentLinkedQueue<byte[]> q2 = arrayPool.putIfAbsent(b.length, q);
if (q2 != null)
q = q2;
}
q.offer(b);
//int pooled = pooledCount.incrementAndGet();
//System.out.println(pooled);
}
示例2: longIdleHeartBeat
import java.util.concurrent.ConcurrentLinkedQueue; //导入方法依赖的package包/类
/**
* check if the connection is not be used for a while & do connection heart beat
*
* @param linkedQueue
* @param hearBeatTime
*/
private void longIdleHeartBeat(ConcurrentLinkedQueue<BackendConnection> linkedQueue, long hearBeatTime) {
long length = linkedQueue.size();
for (int i = 0; i < length; i++) {
BackendConnection con = linkedQueue.poll();
if (con.isClosedOrQuit()) {
continue;
} else if (con.getLastTime() < hearBeatTime) { //if the connection is idle for a long time
con.setBorrowed(true);
new ConnectionHeartBeatHandler().doHeartBeat(con);
} else {
linkedQueue.offer(con);
break;
}
}
}
示例3: testOfferNull
import java.util.concurrent.ConcurrentLinkedQueue; //导入方法依赖的package包/类
/**
* offer(null) throws NPE
*/
public void testOfferNull() {
ConcurrentLinkedQueue q = new ConcurrentLinkedQueue();
try {
q.offer(null);
shouldThrow();
} catch (NullPointerException success) {}
}