我们可以调用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
这里还有很好解释的实际例子:
关于java - LockSupport.park(Object blocker)的参数有什么用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36939218/