public boolean process (ISOSource source, ISOMsg m) { pool.execute (new Processor (source, m)); return false; // let other listeners do their work too } }
public boolean process (ISOSource source, ISOMsg m) { if (pool == null) pool = new ThreadPool (1, 10); pool.execute (new Process (source, m)); return true; } }
@Override public void run() { for (int i = 0; i < 100; i++) { pool.execute(new Job(i, this)); } } }
getPool().execute (new ProcessorRunner (f));
@Test public void testRunNames() throws Throwable { ThreadPool threadPool = new ThreadPool(1, 2); threadPool.execute(new TestTask()); ISOUtil.sleep(20); threadPool.execute(new TestTask()); ISOUtil.sleep(20); Thread[] tl = new Thread[threadPool.activeCount()]; threadPool.enumerate(tl); for (Thread t :tl ) assertThat(t.getName(), new Matches("ThreadPool.PooledThread-\\d+-(running|idle)")); }
@Test @SuppressWarnings("deprecation") public void testIssue196 () { ThreadPool pool = new ThreadPool(10, 20, "thepool"); int available = pool.getAvailableCount(); int active = pool.getActiveCount(); long end = System.currentTimeMillis() + 10000L; // run for 10 seconds top int i = 0; while (active >= 0 && System.currentTimeMillis() < end) { while (available > 0) { pool.execute(() -> { }); available = pool.getAvailableCount(); } available = pool.getAvailableCount(); active = pool.getActiveCount(); } assertTrue ("Active should be >= 0 but it is " + active, active >= 0); }
@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()); }
channels.put (channel.getName(), wr); channels.put (LAST, wr); pool.execute (createSession(channel)); setChanged (); notifyObservers (this);
@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()); }