Package java.util.concurrent

Examples of java.util.concurrent.Semaphore.tryAcquire()


         // Reacquire the semaphore tickets; when we have them all
         // we know the threads are done
         for (int i = 0; i < count; i++)
         {
            boolean acquired = semaphore.tryAcquire(60, TimeUnit.SECONDS);
            if (!acquired) fail("failed to acquire semaphore " + i);
         }

         // allow any async calls to clear
         if (!sync)
View Full Code Here


         // Reacquire the semaphore tickets; when we have them all
         // we know the threads are done
         for (int i = 0; i < cacheCount; i++)
         {
            boolean acquired = semaphore.tryAcquire(60, TimeUnit.SECONDS);
            if (!acquired)
            {
               fail("failed to acquire semaphore " + i);
            }
         }
View Full Code Here

            for (CacheStressor stressor : stressors)
            {
               cacheA.getRegion(Fqn.fromString("/" + stressor.getName()), true).activate();
               stressor.stopPuts();
               // Reacquire one semaphore ticket
               boolean acquired = semaphore.tryAcquire(60, TimeUnit.SECONDS);
               if (!acquired)
               {
                  fail("failed to acquire semaphore " + stressor.getName());
               }
View Full Code Here

                Thread.sleep(500);
            }
        }

        // Wait until all updates return
        sem.tryAcquire(15000, TimeUnit.MILLISECONDS);
       
        // Verify that server is following and has the same epoch as the leader
        assertTrue("Not following", qu.getPeer(index).peer.follower != null);
        long epochF = (qu.getPeer(index).peer.getActiveServer().getZxid() >> 32L);
        long epochL = (leader.getEpoch() >> 32L);
View Full Code Here

                }, null);
            }
        }

        // Wait until all updates return
        if(!sem.tryAcquire(20000, TimeUnit.MILLISECONDS)) {
            LOG.warn("Did not aquire semaphore fast enough");
        }
        t.join(10000);
        Thread.sleep(1000);
       
View Full Code Here

                Thread.sleep(1000);
            }
        }

        // Wait until all updates return
        if(!sem.tryAcquire(15000, TimeUnit.MILLISECONDS)) {
            LOG.warn("Did not aquire semaphore fast enough");
        }
        t.join(10000);
        Thread.sleep(1000);
        // Verify that server is following and has the same epoch as the leader
View Full Code Here

        ConnectFuture connectFuture = vmPipeConnector.connect(vmPipeAddress);
        connectFuture.awaitUninterruptibly();
        connectFuture.getSession().write(IoBuffer.wrap(new byte[1])).awaitUninterruptibly();
        connectFuture.getSession().close(false).awaitUninterruptibly();

        semaphore.tryAcquire(1, TimeUnit.SECONDS);
        vmPipeAcceptor.unbind(vmPipeAddress);
        Assert.assertEquals(1, connectFuture.getSession().getWrittenBytes());
        Assert.assertEquals("ABCD", stringBuffer.toString());
    }
}
View Full Code Here

        Thread thread = new Thread(getName()  + " - Shutdown Monitor Thread") {
            @Override
            public void run() {
                try {
                    LOGGER.debug("Waiting for " + shutdownTimeout + " milliseconds to a clean shutdown of SA " + ServiceAssemblyImpl.this.getName());
                    if (!semaphore.tryAcquire(shutdownTimeout, TimeUnit.MILLISECONDS)) {
                        LOGGER.warn("Unable to do a clean shutdown of SA " + ServiceAssemblyImpl.this.getName() + ", canceling all sync exchanges");
                        listener.cancelPendingSyncExchanges(ServiceAssemblyImpl.this);                       
                    }
                } catch (InterruptedException e) {
                    //let's assume things went OK if we got interrupted
View Full Code Here

        dispatch(e);
        Thread thread = Thread.currentThread();
        String original = thread.getName();
        try {
            if (timeout > 0) {
                if (!lock.tryAcquire(timeout, TimeUnit.MILLISECONDS)) {
                    throw new TimeoutException();
                }
            } else {
                thread.setName(original + " (waiting for exchange " + exchange.getId() + ")");
                lock.acquire();
View Full Code Here

            }
        });
       
        // wait for the renderer to run the worker
        try {
            if (!gs.tryAcquire(2, TimeUnit.SECONDS)) {
                out.append("Graphics information unavailable\n");
            }
        } catch (InterruptedException ie) {
            // ignore
           
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.