gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:40:08 26 4
gpt4 key购买 nike

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 接口(interface)的规范。执行者必须注意提交发生在任务执行之前。这不会自己发生。需要同步(等待/通知、 volatile 写入/读取等)。

关于java - 在 Executor.submit() 保证之前发生,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34699892/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com