本文整理匯總了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) {}
}