如何跳出死循环?
在业务代码里判断 JMH是否执行完毕, 然后再做其他操作
@Benchmark
@Group("pingpong")
public void ping(Control cnt) {
while (true) {
if (cnt.stopMeasurement) {
return;
}
boolean setSuccess = flag.compareAndSet(false, true);
if (setSuccess) {
return;
}
}
}
@Benchmark
@Group("pingpong")
public void pong(Control cnt) {
while (true) {
if (cnt.stopMeasurement) {
return;
}
boolean setSuccess = flag.compareAndSet(true, false);
if (setSuccess) {
return;
}
}
}