if (lockObject == null) { // No lock object: only take barrier, recurse. try {
barrierObject.await();
} catch (InterruptedException | BrokenBarrierException e) { thrownew RuntimeException(e);
}
step(l, b);
} elseif (barrierObject != null) { // Have barrier: sync, wait and recurse. synchronized(lockObject) { try {
barrierObject.await();
} catch (InterruptedException | BrokenBarrierException e) { thrownew RuntimeException(e);
}
step(l, b);
}
} else { // Sync, and get next step (which is assumed to have object and barrier). synchronized (lockObject) {
Object lockObject2 = l.remove(0);
CyclicBarrier barrierObject2 = b.remove(0); synchronized(lockObject2) { try {
barrierObject2.await();
} catch (InterruptedException | BrokenBarrierException e) { thrownew RuntimeException(e);
}
step(l, b);
}
}
}
}
}
}
publicstaticvoid main(String[] args) throws Exception { // Eagerly initialize ForkJoinPool as we've seen the class initialization code interfere // with the logic of the test when waiting for threads to be non-runnable. Class.forName(ForkJoinPool.class.getName(), true, ForkJoinPool.class.getClassLoader()); try {
testCluster1();
} catch (Exception e) {
Map<Thread,StackTraceElement[]> stacks = Thread.getAllStackTraces(); for (Map.Entry<Thread,StackTraceElement[]> entry : stacks.entrySet()) {
System.out.println(entry.getKey());
System.out.println(Arrays.toString(entry.getValue()));
} throw e;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.