LockSupport.park(Object blocker)的参数有什么用?
What is the usage of the parameter of LockSupport.park(Object blocker)?
我们可以调用LockSupport.park(Object blocker)来停放当前thread.But参数的用法是什么"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.park(Object blocker)来停放当前thread.But参数的用法是什么"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
这里还有很好解释的实际例子: