如何以编程方式检测当前 JVM 是否已被远程调试器连接?
我面临的情况是,当我在子线程中调试代码时,其包装 future 有超时,我总是在外部 future.get(timeout
) 上得到 TimeoutException,我的想法如果我知道调试器已连接,我可以动态放大 future.get() 的 timeout
参数
The situation that I'm facing is when I debug my code in a sub-thread, whose wrapping future has a timeout, I always get a TimeoutException on the outter future.get(timeout
), my idea is if I can know that a debugger is connected, I can dynamically enlarge the timeout
parameter of the future.get()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查找是否已附加调试器的一种选择是检查名为“JDWP Command Reader”的线程是否正在运行:
但是,我建议不要以编程方式检测调试器。一般来说,应用程序行为永远不应该依赖于调试器的存在,否则它会破坏调试真实应用程序的整个想法。最好从外部显式配置
timeout
。One option to find if debugger is attached is to check whether a thread named "JDWP Command Reader" is running:
However, I'd suggest against detecting debugger programmatically. In general, application behavior should never depend on the presence of debugger, otherwise it ruins the entire idea of debugging the real application. It's probably better to make
timeout
explicitly configurable from outside.