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

标签 java java.util.concurrent

我们可以调用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/

相关文章:

java - Hibernate 与 HSQLDB 和 Oracle

multithreading - CountDownLatch 中 await() 的目的是什么?

java - 如何包装 ConcurrentSkipListSet 以线程安全的方式保持最新值的固定容量?

java - 空指针异常问题

java - Canvas 错误地绘制表 itext7 中的高度单元格

java - future 的取消方法文档

android - 成千上万的 java.util.concurrent.TimeoutException : android. os.BinderProxy.finalize() 在 crashlytics 中出现 10 秒异常后超时

java - java HashMap中的ConcurrentModificationException程序

java - <c :out/> unknown tag

java - 如何通过Java文件运行adb命令?