Package EDU.oswego.cs.dl.util.concurrent

Examples of EDU.oswego.cs.dl.util.concurrent.CyclicBarrier


   * @return process exit value (return code) or -1 if timed out.
   * @throws IOException
   */
  public int exec() throws IOException {
    Process proc = Runtime.getRuntime().exec(_command);
    _barrier = new CyclicBarrier(3 + ((_stdin != null) ? 1 : 0));

    PullerThread so =
      new PullerThread("STDOUT", proc.getInputStream(), _stdout);
    so.setDaemon(true);
    so.start();
View Full Code Here


    public void testConcurrentRequests() throws Exception {

        final int WORKERS = 100;
        final int MESSAGE_COUNT = 10;
        final CyclicBarrier barrier = new CyclicBarrier(WORKERS);
        final CountDown finished = new CountDown(WORKERS);

        for (int i = 0; i < WORKERS; i++) {

            new Thread() {
                /**
                 * @see java.lang.Thread#run()
                 */
                public void run() {
                    try {
                        barrier.barrier();

                        for (int i = 0; i < MESSAGE_COUNT; i++)
                            sp.sendDown(getDatagramPacket());


View Full Code Here

    public void testConcurrentRequests() throws Exception {
       
        final int WORKERS = 100;
        final int MESSAGE_COUNT=10;
        final CyclicBarrier barrier = new CyclicBarrier(WORKERS);

        for( int i=0; i < WORKERS; i++ ) {               
       
            new Thread() {
                /**
                 * @see java.lang.Thread#run()
                 */
                public void run() {
                    try {
                        String text = "Hello World";
                        MarshalledObject object = client.createMarshalledObject();
                        object.set(text);
                        Msg msg = client.createMsg();
                        msg.pushMarshaledObject(object);
                               
                        barrier.barrier();
                       
                        for(int i=0; i < MESSAGE_COUNT; i++ )        
                            client.sendRequest(connectURI,msg);
                       
                       
View Full Code Here

    * </ol>
    */
   public void testReadUncommitted() throws Throwable {
      final LockStrategy s=new LockStrategyReadUncommitted();
      final FIFOSemaphore sem=new MyFIFOSemaphore(1);
      final CyclicBarrier barrier=new CyclicBarrier(2);

      Thread t1=new Thread("t1") {
         Sync lock=null;

         public void run() {
            try {
               sem.acquire(); // we're first to the semaphore

               // log("waiting on barrier");
               barrier.barrier(); // wait until t2 joins us
               // log("passed barrier");
               lock=s.readLock();
               lock.attempt(TIMEOUT);
               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)
               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);
            }
            catch(Throwable ex) {
               t1_ex=ex;
            }
            finally {
               if(lock != null)
                  lock.release();
               sem.release();
            }
         }
      };


      Thread t2=new Thread("t2") {
         Sync lock=null;

         public void run() {
            try {
               TestingUtil.sleepThread(100);
               barrier.barrier();
               sem.acquire();
               lock=s.writeLock();
               lock.attempt(TIMEOUT);
               log("changing value from " + value + " to 20");
               value=20;
View Full Code Here

                else
                {
                    try
                    {
                        int concurrent = 100;
                        CyclicBarrier barrier = new CyclicBarrier( concurrent );
                        int cnt = Integer.parseInt( cntStr );
                        int average = Math.max( cnt / concurrent, 1 );

                        while( cnt > 0 )
                        {
View Full Code Here

/* 1302 */           pshr = (Fraction)SynchronizationTimer.this.contention_.get();
/*      */         }
/* 1304 */         while (!entry.isEnabled(nthreads, pshr));
/*      */
/* 1306 */         SynchronizationTimer.BarrierTimer timer = new SynchronizationTimer.BarrierTimer();
/* 1307 */         CyclicBarrier barrier = new CyclicBarrier(nthreads + 1, timer);
/*      */
/* 1309 */         Class cls = entry.cls;
/* 1310 */         Class chanCls = entry.buffCls;
/*      */         try
/*      */         {
/* 1313 */           SwingUtilities.invokeAndWait(new Runnable(cell) {
/*      */             public void run() {
/* 1315 */               this.val$cell.setForeground(Color.blue);
/* 1316 */               this.val$cell.setText("RUN");
/* 1317 */               this.val$cell.repaint();
/*      */             } } );
/*      */         }
/*      */         catch (InvocationTargetException ex) {
/* 1322 */           ex.printStackTrace();
/* 1323 */           System.exit(-1);
/*      */         }
/* 1325 */         synchronized (RNG.constructionLock) {
/* 1326 */           RNG.reset(nthreads);
/*      */
/* 1328 */           if (chanCls == null) {
/* 1329 */             RNG shared = (RNG)cls.newInstance();
/* 1330 */             for (int k = 0; k < nthreads; k++) {
/* 1331 */               RNG pri = (RNG)cls.newInstance();
/* 1332 */               TestLoop l = new TestLoop(shared, pri, pshr, iters, barrier);
/* 1333 */               Threads.pool.execute(l.testLoop());
/*      */             }
/*      */           }
/*      */           else {
/* 1337 */             Channel shared = (Channel)chanCls.newInstance();
/* 1338 */             if (nthreads == 1) {
/* 1339 */               ChanRNG single = (ChanRNG)cls.newInstance();
/* 1340 */               single.setSingle(true);
/* 1341 */               PCTestLoop l = new PCTestLoop(single.getDelegate(), single, pshr,
/* 1342 */                 iters, barrier,
/* 1343 */                 shared, shared);
/* 1344 */               Threads.pool.execute(l.testLoop(true));
/*      */             } else {
/* 1346 */               if (nthreads % 2 != 0) {
/* 1347 */                 throw new Error("Must have even number of threads!");
/*      */               }
/* 1349 */               int npairs = nthreads / 2;
/*      */
/* 1351 */               for (int k = 0; k < npairs; k++) {
/* 1352 */                 ChanRNG t = (ChanRNG)cls.newInstance();
/* 1353 */                 t.setSingle(false);
/* 1354 */                 Channel chan = (Channel)chanCls.newInstance();
/*      */
/* 1356 */                 PCTestLoop l = new PCTestLoop(t.getDelegate(), t, pshr,
/* 1357 */                   iters, barrier,
/* 1358 */                   shared, chan);
/*      */
/* 1360 */                 Threads.pool.execute(l.testLoop(false));
/* 1361 */                 Threads.pool.execute(l.testLoop(true));
/*      */               }
/*      */             }
/*      */
/*      */           }
/*      */
/* 1367 */           if (SynchronizationTimer.this.echoToSystemOut.get()) {
/* 1368 */             System.out.print(
/* 1369 */               entry.name + " " +
/* 1370 */               nthreads + "T " +
/* 1371 */               pshr + "S " +
/* 1372 */               RNG.computeLoops.get() + "I " +
/* 1373 */               RNG.syncMode.get() + "Lm " +
/* 1374 */               RNG.timeout.get() + "TO " +
/* 1375 */               RNG.producerMode.get() + "Pm " +
/* 1376 */               RNG.consumerMode.get() + "Cm " +
/* 1377 */               RNG.bias.get() + "B " +
/* 1378 */               DefaultChannelCapacity.get() + "C " +
/* 1379 */               RNG.exchangeParties.get() + "Xp " +
/* 1380 */               RNG.itersPerBarrier.get() + "Ib : ");
/*      */           }
/*      */
/*      */         }
/*      */
/* 1389 */         barrier.barrier();
/*      */
/* 1391 */         barrier.barrier();
/*      */
/* 1393 */         long tm = timer.getTime();
/* 1394 */         long totalIters = nthreads * iters;
/* 1395 */         double dns = tm * 1000.0D * 10.0D / totalIters;
/* 1396 */         long ns = Math.round(dns);
View Full Code Here

    public void testConcurrentRequests() throws Exception {

        final int WORKERS = 10;
        final int MESSAGE_COUNT = 10;
        final CyclicBarrier barrier = new CyclicBarrier(WORKERS);
        final CountDown finished = new CountDown(WORKERS);

        for (int i = 0; i < WORKERS; i++) {

            new Thread() {
                /**
                 * @see java.lang.Thread#run()
                 */
                public void run() {
                    try {
                        barrier.barrier();

                        for (int i = 0; i < MESSAGE_COUNT; i++)
                            sp.sendDown(allocateDownPacket());


View Full Code Here

TOP

Related Classes of EDU.oswego.cs.dl.util.concurrent.CyclicBarrier

Copyright © 2018 www.massapicom. 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.