Package pt.ul.jarmus.deadlocks.skip

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

package pt.ul.jarmus.deadlocks.skip;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;
import java.util.concurrent.atomic.AtomicReference;

public class FjFj {
  public static void main(String[] args) throws InterruptedException, ExecutionException {
    final AtomicReference<ForkJoinTask<?>> f1 = new AtomicReference<>();
    final AtomicReference<ForkJoinTask<?>> f2 = new AtomicReference<>();
    f1.set(ForkJoinTask.adapt(new Runnable() {
      @Override
      public void run() {
        try {
          f2.get().join();
        } catch (Exception e) {
          throw new RuntimeException(e);
        }
      }
    }));
    f2.set(ForkJoinTask.adapt(new Runnable() {
      @Override
      public void run() {
        try {
          f1.get().join();
        } catch (Exception e) {
          throw new RuntimeException(e);
        }
      }
    }));
    ForkJoinPool pool = new ForkJoinPool();
    pool.submit(f1.get());
    pool.submit(f2.get());
    f1.get().join();
    f2.get().join();
  }
}
TOP

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

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.