Package edu.emory.mathcs.backport.java.util.concurrent

Examples of edu.emory.mathcs.backport.java.util.concurrent.CyclicBarrier


            }
        }, "Thread Name");
       
        long start = System.currentTimeMillis();
        final int WORKER_COUNT=5;
        final CyclicBarrier barrier = new CyclicBarrier(WORKER_COUNT+1);
        for( int i=0; i< WORKER_COUNT; i++ ) {
            new Thread() {
                public void run() {
                    try {
                        barrier.await();
                        for( int i=0; i < ENQUEUE_COUNT/WORKER_COUNT; i++ ) {
                            queue.incrementAndGet();
                            runner.wakeup();
                            yield();
                        }
                    }
                    catch (BrokenBarrierException e) {
                    }
                    catch (InterruptedException e) {
                    }       
                }
            }.start();
        }
        barrier.await();
       
        boolean b = doneCountDownLatch.await(30, TimeUnit.SECONDS);
        long end = System.currentTimeMillis();
        log.info("Iterations: "+iterations.get());
        log.info("counter: "+counter.get());
View Full Code Here


        final AtomicBoolean received = new AtomicBoolean(false);
        final AtomicBoolean delivered = new AtomicBoolean(false);
        final CountDownLatch threadsDone = new CountDownLatch(1);
        final CountDownLatch getPutOrder = new CountDownLatch(1);

        final CyclicBarrier barrier = new CyclicBarrier(2, new Runnable()
        {
            public void run()
            {
                threadsDone.countDown();
            }
        });

        Runnable getCommand = new Runnable()
        {
            public void run()
            {
                try
                {
                    synchronized (lock_)
                    {
                        getPutOrder.countDown();
                        objectUnderTest_.getMessageBlocking();
                    }

                    received.set(true);

                    barrier.await();
                } catch (Exception e)
                {
                    fail();
                }
            }
        };

        Runnable putCommand = new Runnable()
        {
            public void run()
            {
                try
                {
                    getPutOrder.await();

                    objectUnderTest_.enqeue(mesg.getHandle());

                    delivered.set(true);

                    barrier.await();
                } catch (Exception e)
                {
                    fail();
                }
            }
View Full Code Here

        final CountDownLatch threadsDone = new CountDownLatch(1);
        final CountDownLatch getPutOrder = new CountDownLatch(1);
        final AtomicReference getException = new AtomicReference(null);
        final AtomicReference putException = new AtomicReference(null);

        final CyclicBarrier barrier = new CyclicBarrier(2, new Runnable()
        {
            public void run()
            {
                threadsDone.countDown();
            }
        });

        Runnable getCommand = new Runnable()
        {
            public void run()
            {
                try
                {
                    synchronized (lock_)
                    {
                        getPutOrder.countDown();
                        objectUnderTest_.getMessageBlocking();
                    }

                    received.set(true);
                } catch (Exception e)
                {
                    getException.set(e);
                }
                finally
                {
                    try
                    {
                        barrier.await();
                    } catch (InterruptedException e)
                    {
                        // ignored
                    } catch (BrokenBarrierException e)
                    {
                        // should not happen
                        e.printStackTrace();
                    }
                }
            }
        };

        Runnable putCommand = new Runnable()
        {
            public void run()
            {
                try
                {
                    getPutOrder.await();

                    objectUnderTest_.enqeue(mesg.getHandle());

                    delivered.set(true);
                } catch (Exception e)
                {
                    putException.set(e);
                }
                finally
                {
                    try
                    {
                        barrier.await();
                    } catch (InterruptedException e)
                    {
                        // ignored
                    } catch (BrokenBarrierException e)
                    {
View Full Code Here

TOP

Related Classes of edu.emory.mathcs.backport.java.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.