diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/thread/TimeoutTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/thread/TimeoutTest.java index 6cbdb921e23..8833fdb49f8 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/thread/TimeoutTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/thread/TimeoutTest.java @@ -15,6 +15,7 @@ package org.eclipse.jetty.util.thread; import static org.junit.Assert.assertEquals; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicIntegerArray; import org.junit.Before; @@ -131,8 +132,8 @@ public class TimeoutTest public void testStress() throws Exception { final int LOOP=250; - final boolean[] running = {true}; - final AtomicIntegerArray count = new AtomicIntegerArray( 3 ); + final AtomicBoolean running=new AtomicBoolean(true); + final AtomicIntegerArray count = new AtomicIntegerArray( 4 ); timeout.setNow(System.currentTimeMillis()); @@ -144,7 +145,7 @@ public class TimeoutTest @Override public void run() { - while (running[0]) + while (running.get()) { try { @@ -199,18 +200,18 @@ public class TimeoutTest // do the looping until we are stopped int loop=0; - while (running[0]) + while (running.get()) { try { long delay=1000; long wait=100-once; + if (loop++==once) { - // THIS loop is the one time we wait 1000ms + // THIS loop is the one time we wait longer than the delay - count.incrementAndGet( 1 ); - + count.incrementAndGet( 1 ); delay=200; wait=1000; } @@ -228,25 +229,35 @@ public class TimeoutTest e.printStackTrace(); } } + count.incrementAndGet(3); } }; th.start(); } - // run test for 5s - Thread.sleep(8000); - synchronized (lock) - { - running[0]=false; - } - // give some time for test to stop - Thread.sleep(1000); - timeout.tick(System.currentTimeMillis()); - Thread.sleep(500); + long start=System.currentTimeMillis(); + + // run test until all threads are started + while (count.get(0)