如何跳出死循环?

    在业务代码里判断 JMH是否执行完毕, 然后再做其他操作

    1. @Benchmark
    2. @Group("pingpong")
    3. public void ping(Control cnt) {
    4. while (true) {
    5. if (cnt.stopMeasurement) {
    6. return;
    7. }
    8. boolean setSuccess = flag.compareAndSet(false, true);
    9. if (setSuccess) {
    10. return;
    11. }
    12. }
    13. }
    1. @Benchmark
    2. @Group("pingpong")
    3. public void pong(Control cnt) {
    4. while (true) {
    5. if (cnt.stopMeasurement) {
    6. return;
    7. }
    8. boolean setSuccess = flag.compareAndSet(true, false);
    9. if (setSuccess) {
    10. return;
    11. }
    12. }
    13. }