本文整理汇总了Java中java.util.concurrent.LinkedTransferQueue.size方法的典型用法代码示例。如果您正苦于以下问题:Java LinkedTransferQueue.size方法的具体用法?Java LinkedTransferQueue.size怎么用?Java LinkedTransferQueue.size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.LinkedTransferQueue
的用法示例。
在下文中一共展示了LinkedTransferQueue.size方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testTransfer2
import java.util.concurrent.LinkedTransferQueue; //导入方法依赖的package包/类
/**
* transfer waits until a poll occurs. The transfered element
* is returned by the associated poll.
*/
public void testTransfer2() throws InterruptedException {
final LinkedTransferQueue<Integer> q = new LinkedTransferQueue<>();
final CountDownLatch threadStarted = new CountDownLatch(1);
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
threadStarted.countDown();
q.transfer(five);
checkEmpty(q);
}});
threadStarted.await();
Callable<Boolean> oneElement
= new Callable<Boolean>() { public Boolean call() {
return !q.isEmpty() && q.size() == 1; }};
waitForThreadToEnterWaitState(t, oneElement);
assertSame(five, q.poll());
checkEmpty(q);
awaitTermination(t);
}
示例2: testTryTransfer7
import java.util.concurrent.LinkedTransferQueue; //导入方法依赖的package包/类
/**
* tryTransfer waits for any elements previously in to be removed
* before transfering to a poll or take
*/
public void testTryTransfer7() throws InterruptedException {
final LinkedTransferQueue q = new LinkedTransferQueue();
assertTrue(q.offer(four));
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
long startTime = System.nanoTime();
assertTrue(q.tryTransfer(five, LONG_DELAY_MS, MILLISECONDS));
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
checkEmpty(q);
}});
while (q.size() != 2)
Thread.yield();
assertEquals(2, q.size());
assertSame(four, q.poll());
assertSame(five, q.poll());
checkEmpty(q);
awaitTermination(t);
}
示例3: testTransfer3
import java.util.concurrent.LinkedTransferQueue; //导入方法依赖的package包/类
/**
* transfer waits until a poll occurs, and then transfers in fifo order
*/
public void testTransfer3() throws InterruptedException {
final LinkedTransferQueue<Integer> q = new LinkedTransferQueue<>();
Thread first = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
q.transfer(four);
assertFalse(q.contains(four));
assertEquals(1, q.size());
}});
Thread interruptedThread = newStartedThread(
new CheckedInterruptedRunnable() {
public void realRun() throws InterruptedException {
while (q.isEmpty())
Thread.yield();
q.transfer(five);
}});
while (q.size() < 2)
Thread.yield();
assertEquals(2, q.size());
assertSame(four, q.poll());
first.join();
assertEquals(1, q.size());
interruptedThread.interrupt();
interruptedThread.join();
checkEmpty(q);
}
示例4: start
import java.util.concurrent.LinkedTransferQueue; //导入方法依赖的package包/类
@Override
public void start(int numSlots) throws IOException {
if (!setRunning(true)) {
return;
}
// Init buffer slots
loading.set(true);
slots = new ByteSlot[numSlots];
slotsCache = new LinkedTransferQueue();
while (slotsCache.size() < numSlots) {
slotsCache.offer(new ByteSlot());
}
// Tunings
maxRetriesBeforeRoll =
conf.getInt(MAX_RETRIES_BEFORE_ROLL_CONF_KEY, DEFAULT_MAX_RETRIES_BEFORE_ROLL);
maxSyncFailureRoll = conf.getInt(MAX_SYNC_FAILURE_ROLL_CONF_KEY, DEFAULT_MAX_SYNC_FAILURE_ROLL);
waitBeforeRoll = conf.getInt(WAIT_BEFORE_ROLL_CONF_KEY, DEFAULT_WAIT_BEFORE_ROLL);
rollRetries = conf.getInt(ROLL_RETRIES_CONF_KEY, DEFAULT_ROLL_RETRIES);
rollThreshold = conf.getLong(ROLL_THRESHOLD_CONF_KEY, DEFAULT_ROLL_THRESHOLD);
periodicRollMsec = conf.getInt(PERIODIC_ROLL_CONF_KEY, DEFAULT_PERIODIC_ROLL);
syncWaitMsec = conf.getInt(SYNC_WAIT_MSEC_CONF_KEY, DEFAULT_SYNC_WAIT_MSEC);
useHsync = conf.getBoolean(USE_HSYNC_CONF_KEY, DEFAULT_USE_HSYNC);
// Init sync thread
syncThread = new Thread("WALProcedureStoreSyncThread") {
@Override
public void run() {
try {
syncLoop();
} catch (Throwable e) {
LOG.error("Got an exception from the sync-loop", e);
if (!isSyncAborted()) {
sendAbortProcessSignal();
}
}
}
};
syncThread.start();
}