Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Happens-before guarantee of Executor.submit()

Javadoc of Executor interface says the following:

Memory consistency effects: Actions in a thread prior to submitting a Runnable object to an Executor happen-before its execution begins, perhaps in another thread.

Which part of the Java Language Specification guarantees that? Or is it only because the implementations use some internal synchronization? (An example would be great if that's the case.) So when implementing a custom Executor should I be aware of this requirement?

like image 738
mmvv Avatar asked Jan 09 '16 22:01

mmvv


1 Answers

The JLS doesn't specify the API. It specifies the language. The javadoc is the API specification.

And thus yes, if you were to implement an Executor, you'd better comply with the specifications of the Executor interface. The executor must take care that the submission happens-before the execution of the task. That doesn't happen by itself. Synchronization is needed (wait/notify, volatile write/read, etc.).

like image 133
JB Nizet Avatar answered Sep 23 '22 18:09

JB Nizet