Package pt.ul.jarmus.deadlocks.skip

Source Code of pt.ul.jarmus.deadlocks.skip.CyclicFj

package pt.ul.jarmus.deadlocks.skip;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;

import pt.ul.jarmus.JArmus;

public class CyclicFj {

  public static void main(String[] args) throws InterruptedException {
    final CyclicBarrier barrier = new CyclicBarrier(2);
    final ForkJoinPool pool = new ForkJoinPool();
    ForkJoinTask<?> t1 = pool.submit(ForkJoinTask.adapt(new Runnable() { // T1
      @Override
      public void run() {
        JArmus.register(barrier); // Is using the latch
        try {
          ForkJoinTask.adapt(new Runnable() { // T2
            @Override
            public void run() {
              try {
                JArmus.register(barrier); // Is using the latch
                barrier.await(); // wait for T1
              } catch (InterruptedException | BrokenBarrierException e) {
                throw new RuntimeException(e);
              }
            }
          }).invoke(); // wait for T2
          barrier.await();
        } catch (Exception e) {
          throw new RuntimeException(e);
        }
      }
    }));
    t1.join();
  }

}
TOP

Related Classes of pt.ul.jarmus.deadlocks.skip.CyclicFj

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.