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();
}
}