Package java.util.concurrent

Examples of java.util.concurrent.BlockingQueue.take()


        Thread taker=new Thread() {

            public void run() {
                try {
                    System.out.println("taking an element from the queue");
                    queue.take();
                    System.out.println("clear");
                }
                catch(InterruptedException e) {                 
                }
            }
View Full Code Here


      BlockingQueue queue = address2key.get(address);
      try {
         maxNumberInvariant.readLock().lock();
         Object result;
         try {
            result = queue.take();
         } finally {
            maxNumberInvariant.readLock().unlock();
         }
         exitingNumberOfKeys.decrementAndGet();
         return result;
View Full Code Here

               keyProducerStartLatch.open();
               // our address might have been removed from the consistent hash
               if (!address.equals(getAddressForKey(address)))
                  throw new IllegalStateException("Address " + address + " is no longer in the cluster");

               result = queue.take();
            }
         } finally {
            maxNumberInvariant.readLock().unlock();
         }
         exitingNumberOfKeys.decrementAndGet();
View Full Code Here

      BlockingQueue queue = address2key.get(address);
      try {
         maxNumberInvariant.readLock().lock();
         Object result;
         try {
            result = queue.take();
         } finally {
            maxNumberInvariant.readLock().unlock();
         }
         exitingNumberOfKeys.decrementAndGet();
         return result;
View Full Code Here

        executor.execute(new CheckedRunnable() {
            public void realRun() throws InterruptedException {
                threadsStarted.await();
                assertEquals(0, q.remainingCapacity());
                assertSame(one, q.take());
            }
        });

        joinPool(executor);
    }
View Full Code Here

        final CountDownLatch threadStarted = new CountDownLatch(1);
        Thread t = newStartedThread(new CheckedRunnable() {
            public void realRun() {
                threadStarted.countDown();
                try {
                    q.take();
                    shouldThrow();
                } catch (InterruptedException success) {
                }
                assertFalse(Thread.interrupted());
            }
View Full Code Here

        final BlockingQueue q = emptyCollection();
        Thread t = newStartedThread(new CheckedRunnable() {
            public void realRun() {
                Thread.currentThread().interrupt();
                try {
                    q.take();
                    shouldThrow();
                } catch (InterruptedException success) {
                }
                assertFalse(Thread.interrupted());
            }
View Full Code Here

            }
        });

        await(pleaseTake);
        assertEquals(0, q.remainingCapacity());
        assertEquals(0, q.take());

        await(pleaseInterrupt);
        assertThreadStaysAlive(t);
        t.interrupt();
        awaitTermination(t);
View Full Code Here

     */
    @Test
    public void testTake() throws InterruptedException {
        BlockingQueue q = populatedQueue(SIZE);
        for (int i = 0; i < SIZE; ++i) {
            assertEquals(i, q.take());
        }
    }

    /**
     * Take removes existing elements until empty, then blocks interruptibly
View Full Code Here

        final BlockingQueue q = populatedQueue(SIZE);
        final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
        Thread t = newStartedThread(new CheckedRunnable() {
            public void realRun() throws InterruptedException {
                for (int i = 0; i < SIZE; ++i) {
                    assertEquals(i, q.take());
                }

                Thread.currentThread().interrupt();
                try {
                    q.take();
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.