Package pt.ul.jarmus.deadlocks.skip

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

package pt.ul.jarmus.deadlocks.skip;

import java.util.Arrays;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;

import pt.ul.jarmus.JArmus;

public class FjLatchInvokeAll {

  public static void main(String[] args) throws InterruptedException {
    final CountDownLatch latch = new CountDownLatch(1);
    final ForkJoinPool pool = new ForkJoinPool();
    pool.invoke(ForkJoinTask.adapt(new Runnable() { // T
      @Override
      public void run() {
        ForkJoinTask.invokeAll(Arrays.asList(ForkJoinTask.adapt(new Runnable() {
          @Override
          public void run() {
            JArmus.register(latch); // Is using the latch
            try {
              ForkJoinTask.adapt(new Runnable() { // T2
                @Override
                public void run() {
                  try {
                    latch.await(); // wait for T1
                  } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                  }
                }
              }).invoke(); // wait for T2
              latch.countDown();
              latch.await();
            } catch (InterruptedException e) {
              throw new RuntimeException(e);
            }
          }
        }))); // invokeAll
      }
    }));// invoke
  }
}
TOP

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

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.