--- jsr166/src/test/tck/ThreadPoolExecutorTest.java 2004/12/31 14:52:40 1.21 +++ jsr166/src/test/tck/ThreadPoolExecutorTest.java 2005/08/23 12:50:00 1.23 @@ -7,6 +7,7 @@ */ import java.util.concurrent.*; +import java.util.concurrent.atomic.*; import junit.framework.*; import java.util.*; @@ -349,6 +350,9 @@ public class ThreadPoolExecutorTest exte assertSame(q, wq); assertFalse(wq.contains(tasks[0])); assertTrue(wq.contains(tasks[4])); + for (int i = 1; i < 5; ++i) + tasks[i].cancel(true); + p1.shutdownNow(); } catch(Exception e) { unexpectedException(); } finally { @@ -1569,4 +1573,39 @@ public class ThreadPoolExecutorTest exte } } + /** + * execute allows the same task to be submitted multiple times, even + * if rejected + */ + public void testRejectedRecycledTask() { + final int nTasks = 1000; + final AtomicInteger nRun = new AtomicInteger(0); + final Runnable recycledTask = new Runnable() { + public void run() { + nRun.getAndIncrement(); + } }; + final ThreadPoolExecutor p = + new ThreadPoolExecutor(1, 30, 60, TimeUnit.SECONDS, + new ArrayBlockingQueue(30)); + try { + for (int i = 0; i < nTasks; ++i) { + for (;;) { + try { + p.execute(recycledTask); + break; + } + catch (RejectedExecutionException ignore) { + } + } + } + Thread.sleep(5000); // enough time to run all tasks + assertEquals(nRun.get(), nTasks); + } catch(Exception ex) { + ex.printStackTrace(); + unexpectedException(); + } finally { + p.shutdown(); + } + } + }