[英]Can I suspend Java runtime on method entry to have time to attach by debugger or profiler?
Is there a way to suspend all business-logic execution threads of Java process when execution hits some method? 当执行遇到某些方法时,有没有办法暂停Java进程的所有业务逻辑执行线程?
If it is not possible via external configuration is there any method call to embedd into application to achieve desired result? 如果通过外部配置无法实现,是否有任何方法调用嵌入到应用程序中以实现所需的结果?
According to how to profile application startup with visualvm I can start application with 根据如何使用visualvm配置应用程序启动,我可以启动应用程序
-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y
to stop execution on app startup. 停止在应用启动时执行。
May be it would be possible to set breakpoint and move to interesting app state and then attach with profiler and start app again. 也许可以设置断点并转移到有趣的应用程序状态,然后使用分析器附加并再次启动应用程序。
Another option is to start with Java agent: https://visualvm.github.io/startupprofiler.html 另一种选择是从Java代理开始: https : //visualvm.github.io/startupprofiler.html
One solution is the place this code right before the method you want to debug: System.out.println("Press Any Key To Continue..."); new java.util.Scanner(System.in).nextLine();
一种解决方案是将此代码放在要调试的方法之前:
System.out.println("Press Any Key To Continue..."); new java.util.Scanner(System.in).nextLine();
System.out.println("Press Any Key To Continue..."); new java.util.Scanner(System.in).nextLine();
This waits until you press enter, so you have time to attach your debugger. 这等待直到您按Enter键,因此您有时间附加调试器。
Another method is to use the IDE Netbeans, which contains a debugger and allows you to set breakpoints anywhere. 另一种方法是使用IDE Netbeans,它包含一个调试器,允许您在任何地方设置断点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.