在造挡板数据mock的时候遇到了一种场景,就是在调用一个接口a的时候,会异步请求接口b,这样在些挡板数据的时候就对接口b的请求新开了一个线程。
写的时候都没有遇到什么问题,但是在运行的时候总是拿不到异步返回的数据,所以尝试着debug调试一下,但以前也仅仅是对一个线程进行debug,现在多个debug,还真不会,一番百度谷歌搜索后,终于找到方法,现在分享一下。
模拟多线程写了个测试类:
public static void main(String[] args) throws Exception {
String test = "begin";
System.out.println(test);
//线程1
new Thread("Thread1-Name") {
@Override
public void run() {
System.out.println("Thread1-Name Start");//断点处
try {
Thread.sleep(1000);
decryptByPublicKey();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Thread1-Name end");
}
}.start();
//线程2
new Thread(&#