一段模拟并发测试的java代码
最近在做系统的并发调优,发现用jmete模拟并发效果不太好,可能是自己不太会使用,所以自己写了一段模拟并发请求的代码
/**
* 回调通知性能测试
*/
@Test
public void notifyPay(){
String[] ids = {"616704025123028992","616704025115336704","618854829254705152","613060490263691264"};
while (true){
CountDownLatch count = new CountDownLatch(1);
for(int i =0;i<ids.length;i++){
int finalI = i;
new Thread(new Runnable() {
@Override
public void run() {
try {
//等待一起执行
count.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
//TODO 这里写需要并发的业务接口调用
// notifyPayFeign.notifySend(ids[finalI]);
}
}).start();
}
count.countDown();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}