Package java.util.concurrent

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


                if(i == 0)
                    channels[i]=new ConcurrentStartupChannel(names[i], semaphore);
                else
                    channels[i]=new ConcurrentStartupChannel((JChannel)channels[0].getChannel(), names[i], semaphore);
                channels[i].start();
                semaphore.release(1);
                if(i == 0)
                    Util.sleep(1500); // sleep after the first node to educe the chances of a merge
            }

            // Make sure everyone is in sync
View Full Code Here


    public void testSingleChannel() throws Exception {
        Semaphore s = new Semaphore(1);
        FlushTestReceiver receivers[] = new FlushTestReceiver[] { new FlushTestReceiver("c1", s, 0,
                        FlushTestReceiver.CONNECT_ONLY) };
        receivers[0].start();
        s.release(1);

        // Make sure everyone is in sync
        Channel[] tmp = new Channel[receivers.length];
        for (int i = 0; i < receivers.length; i++)
            tmp[i] = receivers[i].getChannel();
View Full Code Here

                }
                channels.add(channel);

                // Release one ticket at a time to allow the thread to start working
                channel.start();
                semaphore.release(1);
                if (first)
                    Util.sleep(3000); // minimize changes of a merge happening
                first = false;
            }
View Full Code Here

               // log("passed barrier");
               lock = s.readLock();
               lock.tryLock(TIMEOUT, TimeUnit.MILLISECONDS);
               log("1st read: value is " + value);
               assertEquals(10, value);
               sem.release(); // give t2 time to make the modification
               TestingUtil.sleepThread(100);

               sem.acquire(); // to read the uncommitted modification by t2
               log("2nd read: value is " + value + "; we should see t2's uncommitted change (20)");
               assertEquals(20, value); // we're seeing the modification by t2 before t2 committed (a.k.a. released the lock)
View Full Code Here

               TestingUtil.sleepThread(100);

               sem.acquire(); // to read the uncommitted modification by t2
               log("2nd read: value is " + value + "; we should see t2's uncommitted change (20)");
               assertEquals(20, value); // we're seeing the modification by t2 before t2 committed (a.k.a. released the lock)
               sem.release();
               TestingUtil.sleepThread(100);

               sem.acquire(); // to read the committed change by t2
               log("3rd read: value is still " + value + "; we should see t2's committed change");
               assertEquals(20, value);
View Full Code Here

            }
            finally
            {
               if (lock != null)
                  lock.unlock();
               sem.release();
            }
         }
      };

View Full Code Here

               sem.acquire();
               lock = s.writeLock();
               lock.tryLock(TIMEOUT, TimeUnit.MILLISECONDS);
               log("changing value from " + value + " to 20");
               value = 20;
               sem.release(); // now t1 can read the uncommitted modification
               TestingUtil.sleepThread(100);

               sem.acquire(); // to unlock the lock
               log("committing the TX");
               lock.unlock();
View Full Code Here

            }
            finally
            {
               if (lock != null)
                  lock.unlock();
               sem.release();
            }
         }
      };

      t1.start();
View Full Code Here

            }

            for(int i=0;i < apps.length;i++) {
                StateTransferApplication app=apps[i];
                app.start();
                semaphore.release();
                //avoid merge
                Util.sleep(3000);
            }

            // Make sure everyone is in sync
View Full Code Here

        final Semaphore throttle = _throttle;
        throttle.acquireUninterruptibly();
        try {
            compute();
        } finally {
            throttle.release();
        }
    }

}
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.