Java Code Examples for java.util.concurrent.LinkedTransferQueue#isEmpty()
The following examples show how to use
java.util.concurrent.LinkedTransferQueue#isEmpty() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LinkedTransferQueueTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * 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); }
Example 2
Source File: LinkedTransferQueueTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * transfer waits until a poll occurs, at which point the polling * thread returns the element */ public void testTransfer4() throws InterruptedException { final LinkedTransferQueue q = new LinkedTransferQueue(); Thread t = newStartedThread(new CheckedRunnable() { public void realRun() throws InterruptedException { q.transfer(four); assertFalse(q.contains(four)); assertSame(three, q.poll()); }}); while (q.isEmpty()) Thread.yield(); assertFalse(q.isEmpty()); assertEquals(1, q.size()); assertTrue(q.offer(three)); assertSame(four, q.poll()); awaitTermination(t); }
Example 3
Source File: LinkedTransferQueueTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * transfer waits until a take occurs. The transfered element * is returned by the associated take. */ public void testTransfer5() throws InterruptedException { final LinkedTransferQueue<Integer> q = new LinkedTransferQueue<>(); Thread t = newStartedThread(new CheckedRunnable() { public void realRun() throws InterruptedException { q.transfer(four); checkEmpty(q); }}); while (q.isEmpty()) Thread.yield(); assertFalse(q.isEmpty()); assertEquals(1, q.size()); assertSame(four, q.take()); checkEmpty(q); awaitTermination(t); }
Example 4
Source File: LinkedTransferQueueTest.java From j2objc with Apache License 2.0 | 6 votes |
/** * transfer waits until a poll occurs. The transfered element * is returned by this associated poll. */ public void testTransfer2() throws InterruptedException { final LinkedTransferQueue<Integer> q = new LinkedTransferQueue<Integer>(); 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); }
Example 5
Source File: LinkedTransferQueueTest.java From j2objc with Apache License 2.0 | 6 votes |
/** * transfer waits until a poll occurs, at which point the polling * thread returns the element */ public void testTransfer4() throws InterruptedException { final LinkedTransferQueue q = new LinkedTransferQueue(); Thread t = newStartedThread(new CheckedRunnable() { public void realRun() throws InterruptedException { q.transfer(four); assertFalse(q.contains(four)); assertSame(three, q.poll()); }}); while (q.isEmpty()) Thread.yield(); assertFalse(q.isEmpty()); assertEquals(1, q.size()); assertTrue(q.offer(three)); assertSame(four, q.poll()); awaitTermination(t); }
Example 6
Source File: LinkedTransferQueueTest.java From j2objc with Apache License 2.0 | 6 votes |
/** * transfer waits until a take occurs. The transfered element * is returned by this associated take. */ public void testTransfer5() throws InterruptedException { final LinkedTransferQueue<Integer> q = new LinkedTransferQueue<Integer>(); Thread t = newStartedThread(new CheckedRunnable() { public void realRun() throws InterruptedException { q.transfer(four); checkEmpty(q); }}); while (q.isEmpty()) Thread.yield(); assertFalse(q.isEmpty()); assertEquals(1, q.size()); assertSame(four, q.take()); checkEmpty(q); awaitTermination(t); }