Question I've had for years: In this pseudocode,
ExecutorService svc = Executors.newFixedThreadPool(3);
svc.submit(new Runnable() { /* code A */ });
svc.shutdown();
if(svc.awaitTermination(...)) {
// code B
.awaitTermination()
is not documented as establishing happens-before between code A & B. Is there a reason it isn't ?
The ExecutorService and concurrent package javadocs define happens-before between the tasks and work done before they were submitted, but not between executor tasks and code after a successful .awaitTermination()
call.
Note, I'm not asking for design critiques on how to restructure my code to leverage documented happens-before relationships. My question here is, is there a reason the docs don't mention happens-before in this situation?
(Note that this is not a duplicate of 22665198 despite the very apt title.)
ExecutionService
, are you sure? Did you mean ExecutorService
? Also, there is no ExecutorService.awaitTermination()
method without parameters. The ExecutorService.awaitTermination(long, TimeUnit)
method receives the amount of time to wait until timeout. Obviously, if it returns because of the timeout, it cannot guarantee the happens-before relationship, thus it cannot advertise this guarantee in its contract, because it is not there for all cases.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With