Executor.submit() 发生前保证

Happens-before guarantee of Executor.submit()

Javadoc of Executor interface 表示如下:

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.

Java 语言规范的哪一部分保证了这一点?或者仅仅是因为实现使用了一些内部同步? (如果是这样的话,一个例子会很好。)所以在实现自定义时 Executor 我应该知道这个要求吗?

JLS 未指定 API。它指定了语言。 javadoc 是 API 规范。

因此,是的,如果您要实现一个 Executor,您最好遵守 Executor 接口的规范。执行者必须注意提交happens-before任务的执行。这不会自己发生。需要同步(wait/notify、volatile write/read 等)。