Java - 如何检查“ThreadLocal”的值Eclipse 中的变量?
我的网络应用程序中填充了几个 ThreadLocal。而且,在远程调试 web 应用程序时,我想在 Eclipse 中查看这些 ThreadLocal 变量的值(就像 Eclipse 显示其他变量的方式一样)在调试视角的变量选项卡中)。
知道如何在 Eclipse
中调试期间查看 ThreadLocal
变量的值吗?
谢谢!
I have couple of ThreadLocal
s populated in my web app. And, while remote debugging the webapp, I want to see the value of these ThreadLocal
variables in Eclipse
(just like the way Eclipse
shows other variables in the variables tab in Debug perspective).
Any idea how can I view the value of ThreadLocal
variables during debugging in Eclipse
?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当您遇到任何断点时,只需使用视图
Expressions
来显示Thread.currentThread()
的值,您就可以检查每个ThreadLocal值。When you hit any breakpoint, just use view
Expressions
to display the value ofThread.currentThread()
and you will be able to inspect every ThreadLocal value.在您的代码中,您必须将这些值放入您可以看到的局部变量中。您应该能够在使用 ThreadLocal 的地方设置断点。
问题是调试器的连接与您感兴趣的线程位于不同的线程上。Eclipse 可以为此提供解决方案,但我不知道它是什么。
In your code you have to place the values into a local variable, which you can see. You should be able to breakpoint where the ThreadLocal is used.
The problem is that the debugger's connection is on a different thread to the one you are interested in. Eclipse could have a solution for this, but I don't know what it is.
如果您想要更多详细信息,即想要查看所有线程的线程局部变量,以下代码可能会有所帮助:
您可以将
MyClass.printThreadLocal()
添加到Expressions
。If you want more details i.e. want to see the threadlocal variables for all the threads following code might help:
You can add
MyClass.printThreadLocal()
toExpressions
.