--- jsr166/src/test/tck/ThreadPoolExecutorTest.java 2004/01/20 20:30:08 1.18 +++ jsr166/src/test/tck/ThreadPoolExecutorTest.java 2004/04/12 12:03:10 1.20 @@ -36,6 +36,15 @@ public class ThreadPoolExecutorTest exte } } + static class FailingThreadFactory implements ThreadFactory{ + int calls = 0; + public Thread newThread(Runnable r){ + if (++calls > 1) return null; + return new Thread(r); + } + } + + /** * execute successfully executes a runnable */ @@ -1498,5 +1507,22 @@ public class ThreadPoolExecutorTest exte } } - + /** + * Execution continues if there is at least one thread even if + * thread factory fails to create more + */ + public void testFailingThreadFactory() { + ExecutorService e = new ThreadPoolExecutor(100, 100, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(), new FailingThreadFactory()); + try { + ArrayList> l = new ArrayList>(); + for (int k = 0; k < 100; ++k) { + e.execute(new NoOpRunnable()); + } + Thread.sleep(LONG_DELAY_MS); + } catch(Exception ex) { + unexpectedException(); + } finally { + joinPool(e); + } + } }