java调试技术_java 调试技巧

远程调试

1、远程调试是指,开发者可以通过网络连接在远端运行的JVM(例如服务器上运行的应用),并设置断点进行debug。

2、JVM远程调试使用的协议是JDWP(Java Debug Wire Protocol)。

3、使用idea远程调试应用的步骤

1):在远端启动应用时需要在jvm参数中指定开启JDWP功能。 示例: java -jar -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005 debug_xx.jar

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

For example, to launch the JVM with debug options to listen on an address, we use the following option with the java executable:

java-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8000... MainClass

The-agentlib:jdwp with the comma-separated key-value suboptions instruct the JVM to load the JDWP agent and wait for a socket connection on port 8000. Here’s what each suboption does:

transport=dt_socket tells the JDWP agent to use socket transport.

server=y means that the JVM will listen fora debugger to attach to it.

suspend=y means the JVM will wait for the debugger to attach before executing the main class. This is also the default value. If set to n, the JVM will immediately execute the main class, while listening forthe debugger connection.

address=8000 specifies the address at which the debug socket will listen. In this case, the JVM will listen at port 8000 for incoming connections only from the local host (starting JDK 9).

View Code

2):使用idea连接远端JVM并调试。 从idea的Run->Edit Configurations菜单中,新建一个Remote类型的启动配置,启动该配置即可调试应用。配置信息图示如下:

72bf98edf1b817afb8c527dcdf95d175.png

idea中设置条件断点

1、在idea中代码左侧行号处,单击生成一个断点

2、右键点击表示断点的小圆点,弹出debug弹窗,在condition中编写条件表达式。图示如下:

7d5001ea4db0759527ab0c5184e08975.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值