// Java远程调试示例代码
// 1. 在启动Java应用程序时,添加以下JVM参数以启用远程调试:
// -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
public class RemoteDebugExample {
public static void main(String[] args) {
System.out.println("Starting application...");
// 模拟一些业务逻辑
for (int i = 0; i < 10; i++) {
System.out.println("Processing step " + i);
try {
Thread.sleep(1000); // 每次处理之间暂停1秒
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.println("Application finished.");
}
}
启动参数:
agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
:这是用于启用远程调试的JVM参数。transport=dt_socket
:使用套接字传输。server=y
:表示当前进程是服务器端,等待调试器连接。suspend=n
:表示程序启动时不挂起,直接运行。如果设置为y
,则程序会在启动时挂起,直到调试器连接。address=5005
:指定调试器连接的端口号。代码逻辑:
连接调试器:
下一篇:java中instanceof
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站