@Override public int getJobCount () { return pool.getJobCount(); } @Override
public void dump (PrintStream p, String indent) { String inner = indent + " "; p.println (indent + "<thread-pool name=\""+getName()+"\">"); if (!pool.ready()) p.println (inner + "<closed/>"); p.println (inner + "<jobs>" + getJobCount() + "</jobs>"); p.println (inner + "<size>" + getPoolSize() + "</size>"); p.println (inner + "<max>" + getMaxPoolSize() + "</max>"); p.println (inner + "<active>" + getActiveCount() + "</active>"); p.println (inner + "<idle>" + getIdleCount() + "</idle>"); p.println (inner + "<active>" + getActiveCount() + "</active>"); p.println (inner + "<pending>" + getPendingCount() + "</pending>"); p.println (indent + "</thread-pool>"); }
@Test public void testConstructor2() throws Throwable { ThreadPool threadPool = new ThreadPool(0, 100); assertEquals("threadPool.getJobCount()", 0, threadPool.getJobCount()); assertEquals("threadPool.getPoolSize()", 1, threadPool.getPoolSize()); assertEquals("threadPool.getMaxPoolSize()", 100, threadPool.getMaxPoolSize()); }
@Test public void testConstructor() throws Throwable { ThreadPool threadPool = new ThreadPool(-1, 1); assertEquals("threadPool.getJobCount()", 0, threadPool.getJobCount()); assertEquals("threadPool.getPoolSize()", 1, threadPool.getPoolSize()); assertEquals("threadPool.getMaxPoolSize()", 1, threadPool.getMaxPoolSize()); }
@Test public void testConstructor1() throws Throwable { ThreadPool threadPool = new ThreadPool(-2, -1); assertEquals("threadPool.getJobCount()", 0, threadPool.getJobCount()); assertEquals("threadPool.getPoolSize()", 1, threadPool.getPoolSize()); assertEquals("threadPool.getMaxPoolSize()", 100, threadPool.getMaxPoolSize()); }
@Test public void testConstructor3() throws Throwable { ThreadPool threadPool = new ThreadPool(1, 0); assertEquals("threadPool.getJobCount()", 0, threadPool.getJobCount()); assertEquals("threadPool.getPoolSize()", 1, threadPool.getPoolSize()); assertEquals("threadPool.getMaxPoolSize()", 100, threadPool.getMaxPoolSize()); }
@Test public void testConstructor4() throws Throwable { ThreadPool threadPool = new ThreadPool(2, 100); assertEquals("threadPool.getJobCount()", 0, threadPool.getJobCount()); assertEquals("threadPool.getPoolSize()", 2, threadPool.getPoolSize()); assertEquals("threadPool.getMaxPoolSize()", 100, threadPool.getMaxPoolSize()); }
@Test public void testRun1() throws Throwable { ThreadPool threadPool = new ThreadPool(1, 100); ISOUtil.sleep(50); threadPool.execute(new TestTask()); ISOUtil.sleep(50); assertEquals("threadPool.getJobCount()", 1, threadPool.getJobCount()); assertEquals("threadPool.getPoolSize()", 1, threadPool.getPoolSize()); assertEquals("threadPool.getMaxPoolSize()", 100, threadPool.getMaxPoolSize()); ISOUtil.sleep(500); assertEquals("threadPool.getJobCount()", 1, threadPool.getJobCount()); assertEquals("threadPool.getPoolSize()", 1, threadPool.getPoolSize()); }
@Test public void testRun2() throws Throwable { ThreadPool threadPool = new ThreadPool(1, 1); threadPool.execute(new TestTask()); threadPool.execute(new TestTask()); ISOUtil.sleep(50); assertEquals("threadPool.getJobCount()", 2, threadPool.getJobCount()); assertEquals("threadPool.getPoolSize()", 1, threadPool.getPoolSize()); assertEquals("threadPool.getMaxPoolSize()", 1, threadPool.getMaxPoolSize()); assertEquals("threadPool.getPendingCount()", 1, threadPool.getPendingCount()); ISOUtil.sleep(500); assertEquals("threadPool.getJobCount()", 2, threadPool.getJobCount()); assertEquals("threadPool.getPoolSize()", 1, threadPool.getPoolSize()); assertEquals("threadPool.getPendingCount()", 0, threadPool.getPendingCount()); assertEquals("threadPool.getMaxPoolSize()", 1, threadPool.getMaxPoolSize()); ISOUtil.sleep(550); assertEquals("threadPool.getJobCount()", 2, threadPool.getJobCount()); assertEquals("threadPool.getPoolSize()", 1, threadPool.getPoolSize()); assertEquals("threadPool.getMaxPoolSize()", 1, threadPool.getMaxPoolSize()); }
@Test public void testRun3() throws Throwable { ThreadPool threadPool = new ThreadPool(1, 2); threadPool.execute(new TestTask()); ISOUtil.sleep(20); threadPool.execute(new TestTask()); ISOUtil.sleep(20); assertEquals("threadPool.getJobCount()", 2, threadPool.getJobCount()); assertEquals("threadPool.getPoolSize()", 2, threadPool.getPoolSize()); assertEquals("threadPool.getMaxPoolSize()", 2, threadPool.getMaxPoolSize()); }