简体   繁体   English

我可以在方法入口上暂停Java运行时以便有时间通过​​调试器或分析器附加吗?

[英]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.

相关问题 在Nuix中调试Java应用程序-附加探查器或调试器 - Debug Java Application in Nuix - Attach a Profiler or Debugger 如何附加远程 java 调试器来调试 rundeck 插件? - How can I attach a remote java debugger for debugging a rundeck plugin? 我可以在 Azure Application Insights 中获得 Java webapp 的探查器跟踪吗? - Can I have profiler traces for a Java webapp in Azure Application Insights? Java:我可以在运行时将运行时异常注入到任意类方法中吗? - Java: Can I Inject a runtime exception into an arbitrary class method at runtime? Java调试器:是否可以选择性地挂起线程? - Java Debugger: Is it possible selectively suspend threads? 分离后可以将调试器附加到Java进程吗? - Can you attach a debugger to a Java process after detaching? 安装jdk1.8.0_25后,我在注册表中没有“ Java Runtime Envrionment”条目 - after installing jdk1.8.0_25 I do not have a 'Java Runtime Envrionment' entry in Registry 如何在Eclipse中将Java应用程序附加到jvm profiler? - How to attach a Java application to jvm profiler in eclipse? 如何修复“附加调试器或 ESC 以取消”错误? - How can I fix "Attach a Debugger or ESC to Cancel" error? 如何在运行时访问Java编译时间参数? - How can I access a java compile time parameter at runtime?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM