本文整理汇总了Java中java.util.concurrent.ConcurrentLinkedQueue.poll方法的典型用法代码示例。如果您正苦于以下问题:Java ConcurrentLinkedQueue.poll方法的具体用法?Java ConcurrentLinkedQueue.poll怎么用?Java ConcurrentLinkedQueue.poll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.ConcurrentLinkedQueue
的用法示例。
在下文中一共展示了ConcurrentLinkedQueue.poll方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: takeIdleCon
import java.util.concurrent.ConcurrentLinkedQueue; //导入方法依赖的package包/类
public BackendConnection takeIdleCon(boolean autoCommit) {
ConcurrentLinkedQueue<BackendConnection> f1 = autoCommitCons;
ConcurrentLinkedQueue<BackendConnection> f2 = manCommitCons;
if (!autoCommit) {
f1 = manCommitCons;
f2 = autoCommitCons;
}
BackendConnection con = f1.poll();
if (con == null || con.isClosedOrQuit()) {
con = f2.poll();
}
if (con == null || con.isClosedOrQuit()) {
return null;
} else {
return con;
}
}
示例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: takeIdleCon
import java.util.concurrent.ConcurrentLinkedQueue; //导入方法依赖的package包/类
public BackendConnection takeIdleCon(boolean autoCommit) {
ConcurrentLinkedQueue<BackendConnection> f1 = autoCommitCons;
ConcurrentLinkedQueue<BackendConnection> f2 = manCommitCons;
if (!autoCommit) {
f1 = manCommitCons;
f2 = autoCommitCons;
}
BackendConnection con = f1.poll();
if (con == null || con.isClosedOrQuit()) {
con = f2.poll();
}
if (con == null || con.isClosedOrQuit()) {
return null;
} else {
return con;
}
}
示例4: cascadeExecuteCachedTransaction
import java.util.concurrent.ConcurrentLinkedQueue; //导入方法依赖的package包/类
public void cascadeExecuteCachedTransaction(TransactionId pTrxId,boolean trxStatus){
ConcurrentLinkedQueue<LogProcessContext> queue = compensationLogContextCache.getIfPresent(pTrxId);
if(queue == null) {
return ;
}
for(LogProcessContext logContext = queue.poll(); logContext != null; logContext = queue.poll()){
compensationLogContextCache.invalidate(pTrxId);
logContext.setFinalMasterTransStatus(trxStatus);
//asynchronous execute to enhance efficient
executor.execute(getRunnableCompensation(logContext));
}
}
示例5: toHandle
import java.util.concurrent.ConcurrentLinkedQueue; //导入方法依赖的package包/类
public List<JTextComponent> toHandle(ConcurrentLinkedQueue<JTextComponent> q) {
List<JTextComponent> rs = new LinkedList<JTextComponent>();
JTextComponent tx;
while((tx = q.poll()) != null) {
rs.add(tx);
}
return rs;
}
示例6: testConcurrency_MultiInstance_Ordering
import java.util.concurrent.ConcurrentLinkedQueue; //导入方法依赖的package包/类
@Test
public void testConcurrency_MultiInstance_Ordering() throws InterruptedException {
final ConcurrentLinkedQueue<Thread> queue = new ConcurrentLinkedQueue<>();
final AtomicInteger lockedCounter = new AtomicInteger();
int totalThreads = Runtime.getRuntime().availableProcessors()*2;
for (int i = 0; i < totalThreads; i++) {
Thread t1 = new Thread(() -> {
Lock lock = redisson.getFairLock("testConcurrency_MultiInstance2");
queue.add(Thread.currentThread());
lock.lock();
Thread t = queue.poll();
assertThat(t).isEqualTo(Thread.currentThread());
try {
Thread.sleep(1000);
} catch (Exception e) {
e.printStackTrace();
}
lockedCounter.incrementAndGet();
lock.unlock();
});
Thread.sleep(10);
t1.start();
}
await().atMost(30, TimeUnit.SECONDS).until(() -> assertThat(lockedCounter.get()).isEqualTo(totalThreads));
}
示例7: fetchQueue
import java.util.concurrent.ConcurrentLinkedQueue; //导入方法依赖的package包/类
private String fetchQueue(ConcurrentLinkedQueue<String> queue, int maxtime) {
StringBuilder resultString = new StringBuilder();
Long startTime = DateTimeHelper.getCurrentTime();
if (queue.peek() == null) {
return "";
}
String queueString = "";
while (true) {
queueString = queue.poll();
if (queueString != null) {
if (queueString.trim().length() > 0) {
resultString.append(queueString + "\n");
}
} else {
try {
Thread.sleep(10);
} catch (Exception e) {
//log.error(e.getMessage());
}
}
if ((DateTimeHelper.getCurrentTime() - startTime) > maxtime || resultString.length() > processMaxCount) {
break;
}
}
return resultString.toString();
}
示例8: testContains
import java.util.concurrent.ConcurrentLinkedQueue; //导入方法依赖的package包/类
/**
* contains(x) reports true when elements added but not yet removed
*/
public void testContains() {
ConcurrentLinkedQueue q = populatedQueue(SIZE);
for (int i = 0; i < SIZE; ++i) {
assertTrue(q.contains(new Integer(i)));
q.poll();
assertFalse(q.contains(new Integer(i)));
}
}
示例9: takeIdleCon
import java.util.concurrent.ConcurrentLinkedQueue; //导入方法依赖的package包/类
public RedisBackendConnection takeIdleCon() {
ConcurrentLinkedQueue<RedisBackendConnection> f1 = cons;
RedisBackendConnection con = f1.poll();
if (con == null || con.isClosed() || !con.isConnected() ) {
return null;
} else {
return con;
}
}
示例10: cleanup
import java.util.concurrent.ConcurrentLinkedQueue; //导入方法依赖的package包/类
private static void cleanup(ConcurrentLinkedQueue<byte[]> q)
{
if (q != null)
while (q.poll() != null)
{
//pooledCount.decrementAndGet();
}
}
示例11: testCacheMultiThreaded
import java.util.concurrent.ConcurrentLinkedQueue; //导入方法依赖的package包/类
public static void testCacheMultiThreaded(final BlockCache toBeTested,
final int blockSize, final int numThreads, final int numQueries,
final double passingScore) throws Exception {
Configuration conf = new Configuration();
MultithreadedTestUtil.TestContext ctx = new MultithreadedTestUtil.TestContext(
conf);
final AtomicInteger totalQueries = new AtomicInteger();
final ConcurrentLinkedQueue<HFileBlockPair> blocksToTest = new ConcurrentLinkedQueue<HFileBlockPair>();
final AtomicInteger hits = new AtomicInteger();
final AtomicInteger miss = new AtomicInteger();
HFileBlockPair[] blocks = generateHFileBlocks(numQueries, blockSize);
blocksToTest.addAll(Arrays.asList(blocks));
for (int i = 0; i < numThreads; i++) {
TestThread t = new MultithreadedTestUtil.RepeatingTestThread(ctx) {
@Override
public void doAnAction() throws Exception {
if (!blocksToTest.isEmpty()) {
HFileBlockPair ourBlock = blocksToTest.poll();
// if we run out of blocks to test, then we should stop the tests.
if (ourBlock == null) {
ctx.setStopFlag(true);
return;
}
toBeTested.cacheBlock(ourBlock.blockName, ourBlock.block);
Cacheable retrievedBlock = toBeTested.getBlock(ourBlock.blockName,
false, false, true);
if (retrievedBlock != null) {
assertEquals(ourBlock.block, retrievedBlock);
toBeTested.evictBlock(ourBlock.blockName);
hits.incrementAndGet();
assertNull(toBeTested.getBlock(ourBlock.blockName, false, false, true));
} else {
miss.incrementAndGet();
}
totalQueries.incrementAndGet();
}
}
};
t.setDaemon(true);
ctx.addThread(t);
}
ctx.startThreads();
while (!blocksToTest.isEmpty() && ctx.shouldRun()) {
Thread.sleep(10);
}
ctx.stop();
if (hits.get() / ((double) hits.get() + (double) miss.get()) < passingScore) {
fail("Too many nulls returned. Hits: " + hits.get() + " Misses: "
+ miss.get());
}
}