当前位置: 首页>>代码示例>>Java>>正文


Java ConcurrentLinkedQueue.poll方法代码示例

本文整理汇总了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;
	}

}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:21,代码来源:ConQueue.java

示例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;
        }
    }
}
 
开发者ID:actiontech,项目名称:dble,代码行数:22,代码来源:PhysicalDatasource.java

示例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;
    }

}
 
开发者ID:actiontech,项目名称:dble,代码行数:21,代码来源:ConQueue.java

示例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));
	}
}
 
开发者ID:QNJR-GROUP,项目名称:EasyTransaction,代码行数:14,代码来源:EasyTransSynchronizer.java

示例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;            
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:UndoRedoSupport.java

示例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));
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:28,代码来源:RedissonFairLockTest.java

示例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();
}
 
开发者ID:weiboad,项目名称:fiery,代码行数:31,代码来源:CurlThread.java

示例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)));
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:ConcurrentLinkedQueueTest.java

示例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;
	}
}
 
开发者ID:variflight,项目名称:feeyo-redisproxy,代码行数:10,代码来源:ConQueue.java

示例10: cleanup

import java.util.concurrent.ConcurrentLinkedQueue; //导入方法依赖的package包/类
private static void cleanup(ConcurrentLinkedQueue<byte[]> q)
{
	if (q != null)
		while (q.poll() != null)
		{
			//pooledCount.decrementAndGet();
		}
}
 
开发者ID:bp2008,项目名称:blueirisviewer,代码行数:9,代码来源:ByteArrayPool.java

示例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());
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:56,代码来源:CacheTestUtils.java


注:本文中的java.util.concurrent.ConcurrentLinkedQueue.poll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。