并发测压service接口
run 和start
等1000个Thread编译完主线程sleep 在一起出发
private static final int MAX_THREADS = 1000;//模拟1000用户请求 做并发调用远程接口
private CountDownLatch cdl = new CountDownLatch(MAX_THREADS);//花名册
@Autowired
JimsOrderService jimsOrderService;
@Test
public void testInterface() throws ExecutionException, InterruptedException {
for(int i = 0; i< MAX_THREADS; i++) {
Thread thread = new Thread(()->{
Map<String, Object> result = null;//远程调订单查询接口
try {
cdl.countDown();//花名册减1
cdl.await();
result = jimsOrderService.queryOrderInfo("xn1234567");
// System.out.println(result);
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
});
thread.start();
}
Thread.sleep(5000);
}