gpt4 book ai didi

java - LockSupport.park(Object blocker)的参数有什么用?

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:53:59 29 4
gpt4 key购买 nike

我们可以调用LockSupport.park(Object blocker)来暂停当前线程。但是参数“blocker”有什么用呢?

最佳答案

来自文档:

The three forms of park each also support a blocker object parameter. This object is recorded while the thread is blocked to permit monitoring and diagnostic tools to identify the reasons that threads are blocked. (Such tools may access blockers using method getBlocker(java.lang.Thread).) The use of these forms rather than the original forms without this parameter is strongly encouraged. The normal argument to supply as a blocker within a lock implementation is this.

还有:

blocker - the synchronization object responsible for this thread parking

您可以在此处阅读更多信息:LockSupport Docs

这里还有很好解释的实际例子:

LockSupport examples

关于java - LockSupport.park(Object blocker)的参数有什么用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36939218/

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