/** * Start thread for execution if not already started. This can avoid the minor delay of the * thread starting later. This will not block till the thread is running, instead letting it * start in the background (usually fine). */ public void prestartExecutionThread() { prestartExecutionThread(false); }
/** * Start thread for execution if not already started. This can avoid the minor delay of the * thread starting later. This will not block till the thread is running, instead letting it * start in the background (usually fine). */ public void prestartExecutionThread() { prestartExecutionThread(false); }
@Override public SchedulerService makeSchedulerService(int poolSize, boolean prestartIfAvailable) { SingleThreadScheduler result = makeAbstractPriorityScheduler(poolSize); if (prestartIfAvailable) { if (prestartIfAvailable) { result.prestartExecutionThread(true); } } return result; }
@Test public void prestartExecutionThreadTest() { SingleThreadScheduler sts = new SingleThreadScheduler(); assertFalse(sts.sManager.execThread.isAlive()); sts.prestartExecutionThread(true); assertTrue(sts.sManager.execThread.isAlive()); }
@Test public void getAliveThreadsTest() { ThreadReferencingThreadFactory tf = makeThreadFactory(); SingleThreadScheduler sts = new SingleThreadScheduler(tf); sts.prestartExecutionThread(true); Thread thread2 = tf.newThread(DoNothingRunnable.instance()); List<Thread> result = tf.getThreads(true); assertEquals(1, result.size()); assertFalse(result.contains(thread2)); // it was never started } }