跳到主要内容

代码调试技巧

Stream流调试

public class MainTest {


public static void main(String[] args) {

long[] dataResult = LongStream.of(10, 11, 52, 49, 5, 94, 105, 88)
.filter(data -> data > 10)
.map(data -> data * 2)
.distinct()
.sorted()
.toArray();
}
}

选择Trace Current Stream Chain:

image-20240908184939340

然后就可以很直观的看到结果:

image-20240908185015335

Flat Mode:

image-20240908185034502

远程服务器调试

  1. 添加一个运行程序Remote JVM Debug,填写好下面的信息:

image-20240908185910314

  1. 服务器启动jar包:
java -Xdebug -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8888 -jar demo-0.0.1-SNAPSHOT.jar

-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8888 可以在上面配置的Command Line里面直接拿到

image-20240908190633161

  1. 然后运行IDEA刚刚位置的程序:
  2. 测试,此时浏览器访问:http://localhost:8080/v1/user/1 可以看到成功进入断点

image-20240908190510968