简体   繁体   English

发生在Executor.submit()的保证之前

[英]Happens-before guarantee of Executor.submit()

Javadoc of Executor interface says the following: Executor接口的Javadoc说明如下:

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. 内存一致性效果:在将Runnable对象提交给Executor之前,线程中的操作发生在执行开始之前,可能在另一个线程中。

Which part of the Java Language Specification guarantees that? Java语言规范的哪一部分保证了这一点? 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? (如果是这样的话,一个例子会很棒。)因此,在实现自定义Executor ,我是否应该了解这一要求?

The JLS doesn't specify the API. JLS未指定API。 It specifies the language. 它指定了语言。 The javadoc is the API specification. javadoc是API规范。

And thus yes, if you were to implement an Executor, you'd better comply with the specifications of the Executor interface. 因此,是的,如果您要实现Executor,您最好遵守Executor接口的规范。 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.). 需要同步(等待/通知,易失性写/读等)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Lock 是否保证发生之前的关系? - Does Lock guarantee a happens-before relationship? Java - Lock保证如何在关系之前发生? - Java - how does Lock guarantee happens-before relationship? JUnit 5 是否保证有序测试方法的先发生关系? - Does JUnit 5 guarantee the happens-before relationship for ordered test methods? .awaitTermination()是否在执行程序中完成工作之前发生了? - Does .awaitTermination() establish happens-before with work done in the executor? JMM 和happens-before - JMM and happens-before 使用双重检查锁定,在保证之前是否发生了对易失性ConcurrentHashMap的放置? - With double-checked locking, does a put to a volatile ConcurrentHashMap have happens-before guarantee? 如果我只需要保证`happens-before`关系,而不是原子性,我应该使用并发类还是同步块? - If I simply need to guarantee `happens-before` relation, and not atomicity, should I use a concurrent class or a synchronized block? 为每个线程创建一个非线程安全对象并使用before-before保证 - Creating one non-thread-safe object per thread and using happens-before guarantee 发生在使用不同的显示器之前 - Happens-before with different monitors 发生前和可变变量 - Happens-before and volatile variable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM