diff --git a/test/framework/src/test/java/org/elasticsearch/test/disruption/LongGCDisruptionTests.java b/test/framework/src/test/java/org/elasticsearch/test/disruption/LongGCDisruptionTests.java index 43a5e9c133e4d..7e27ffaab3e52 100644 --- a/test/framework/src/test/java/org/elasticsearch/test/disruption/LongGCDisruptionTests.java +++ b/test/framework/src/test/java/org/elasticsearch/test/disruption/LongGCDisruptionTests.java @@ -127,18 +127,18 @@ protected Pattern[] getUnsafeClasses() { final LockedExecutor lockedExecutor = new LockedExecutor(); final AtomicLong ops = new AtomicLong(); final Thread[] threads = new Thread[5]; + final Runnable yieldAndIncrement = () -> { + Thread.yield(); // give some chance to catch this stack trace + ops.incrementAndGet(); + }; try { for (int i = 0; i < threads.length; i++) { threads[i] = new Thread(() -> { for (int iter = 0; stop.get() == false; iter++) { if (iter % 2 == 0) { - lockedExecutor.executeLocked(() -> { - Thread.yield(); // give some chance to catch this stack trace - ops.incrementAndGet(); - }); + lockedExecutor.executeLocked(yieldAndIncrement); } else { - Thread.yield(); // give some chance to catch this stack trace - ops.incrementAndGet(); + yieldAndIncrement.run(); } } });