Package java.util.concurrent.locks

Examples of java.util.concurrent.locks.Lock.newCondition()



    public void testInterrupt() throws InterruptedException {

        Lock      lck = new ReentrantLock();
        Condition cnd = lck.newCondition();
        WaitingThread wt = new WaitingThread(cnd, null);

        AwaitThread ath = new AwaitThread(wt, lck, null);
        ath.start();
        Thread.sleep(100); // give extra thread time to block
View Full Code Here



    public void testIllegal() throws InterruptedException {

        Lock      lck = new ReentrantLock();
        Condition cnd = lck.newCondition();
        WaitingThread wt = new WaitingThread(cnd, null);

        try {
            lck.lock();
            wt.wakeup();
View Full Code Here

        workqueue = new AutomaticWorkQueueImpl(UNBOUNDED_MAX_QUEUE_SIZE, INITIAL_SIZE,
                                               UNBOUNDED_HIGH_WATER_MARK,
                                               UNBOUNDED_LOW_WATER_MARK,
                                               DEFAULT_DEQUEUE_TIMEOUT);
        final Lock runLock = new ReentrantLock();
        final Condition runCondition = runLock.newCondition();
        long start = System.currentTimeMillis();
        Runnable doNothing = new Runnable() {
            public void run() {
                runLock.lock();
                try {
View Full Code Here

        // output.
        // The FIFO is simply implemented as a cached array or byte buffers
        // with an offset and a size which is used like a ring buffer.

        final Lock lock = new ReentrantLock();
        final Condition signal = lock.newCondition();
        final Buffer[] buffers = Buffer.allocate();

        /*
         * The task that cycles through the buffers in order to fill them
         * with input.
View Full Code Here

  @Override
  protected void awaitTuple(List<Integer> typesPath, LindaArgs pattern) {
    // First element in room?
    if (!waitRoom.containsKey(pattern)) {
      Lock lock = getLock(typesPath);
      waitRoom.put(pattern, new CountedWaitRoom(lock.newCondition()));
    }
   
    CountedWaitRoom room = waitRoom.get(pattern);
    room.increment();
    room.getChanges().awaitUninterruptibly();
View Full Code Here

    @Test(timeout = 1500l)
    @Ignore("Ignored until Conditions are fully implemented in ReentrantZkLock2")
    public void testConditionWaitsForSignalOtherThread() throws Exception{
        final Lock firstLock = new ReentrantZkLock2(baseLockPath, zkSessionManager);
        final Condition firstCondition = firstLock.newCondition();

        firstLock.lock();
        //fire off a thread that will signal the main process thread
        testService.submit(new Runnable() {
            @Override
View Full Code Here

    @Test(timeout = 1500l)
    @Ignore("Ignored until Conditions are fully implemented in ReentrantZkLock2")
    public void testConditionWaitsForSignalOtherClient() throws Exception{
        final Lock firstLock = new ReentrantZkLock2(baseLockPath, zkSessionManager);
        final Condition firstCondition = firstLock.newCondition();

        firstLock.lock();
        //fire off a thread that will signal the main process thread
        testService.submit(new Callable<Void>() {
            @Override
View Full Code Here

            public Void call() throws Exception{
                final Lock otherClientLock;
                ZooKeeper newZk = newZooKeeper(hostString,timeout);
                try {
                    otherClientLock = new ReentrantZkLock2(baseLockPath, new BaseZkSessionManager(newZk));
                    final Condition otherClientCondition = otherClientLock.newCondition();
                    otherClientLock.lock();
                    System.out.println("Lock acquired on second thread");
                    try{
                        otherClientCondition.signal();
                        System.out.println("Lock signalled on second thread");
View Full Code Here

    @Test(timeout = 1000l)
    @Ignore("Ignored until Conditions are fully implemented in ReentrantZkLock2")
    public void testConditionTimesOut() throws Exception{
        Lock firstLock = new ReentrantZkLock2(baseLockPath,zkSessionManager);
        Condition firstCondition = firstLock.newCondition();

        firstLock.lock();
        boolean timedOut = firstCondition.await(250l, TimeUnit.MILLISECONDS);
        assertTrue("Condition did not time out!",!timedOut);
        firstLock.unlock();
View Full Code Here

    }

    @Test(timeout = 1500l)
    public void testConditionWaitsForSignalOtherThread() throws Exception{
        final Lock firstLock = new ReentrantZkLock(baseLockPath, zkSessionManager);
        final Condition firstCondition = firstLock.newCondition();

        firstLock.lock();
        //fire off a thread that will signal the main process thread
        testService.submit(new Runnable() {
            @Override
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.