@Test public void testDefaultTaskScheduler() throws Exception { ITaskScheduler scheduler = new DefaultTaskScheduler(4, 50000, 50); Assert.assertEquals(4, scheduler.getMaxThreadSize()); IScheduledTask<String> x = scheduler.schedule(this); Assert.assertEquals(1, scheduler.getCurrentWorkerCount()); AtomicInteger yTaskCount = new AtomicInteger(); IScheduledTask<String> y = scheduler.schedule(() -> { yTaskCount.incrementAndGet(); return "Hello, world"; }); String result = x.get(); Assert.assertEquals("Hello World", result); y.get(); Assert.assertEquals(1, yTaskCount.get()); long delayValue = System.currentTimeMillis(); IScheduledTask<String> delayed = scheduler.schedule(() -> "test_string", 20, TimeUnit.MILLISECONDS); delayed.get(); delayValue = System.currentTimeMillis() - delayValue; Assert.assertTrue(String.format("Delay should be at least 20ms, but was %dms!", delayValue), delayValue >= 20); delayValue = System.currentTimeMillis(); delayed = scheduler.schedule(() -> null, 1, TimeUnit.SECONDS); delayed.get(); delayValue = System.currentTimeMillis() - delayValue; Assert.assertTrue(String.format("Delay should be at least 1000ms, but was %dms!", delayValue), delayValue >= 1000); IScheduledTask<Integer> callbackTask = scheduler.schedule(new CallableCounter(), 0, 1, 5); Assert.assertEquals(5, callbackTask.get().intValue()); scheduler.cancelAll(); }
public DefaultTaskScheduler() { this(Runtime.getRuntime().availableProcessors() * 2, DEFAULT_THREAD_LIFE_MILLIS, DEFAULT_THREAD_PAUSE_MILLIS); }
DefaultTaskScheduler implements ITaskScheduler { public DefaultTaskScheduler() { this(Runtime.getRuntime().availableProcessors() * 2, DEFAULT_THREAD_LIFE_MILLIS, DEFAULT_THREAD_PAUSE_MILLIS); } }
DefaultTaskScheduler implements ITaskScheduler { public DefaultTaskScheduler() { this(Runtime.getRuntime().availableProcessors() * 2, DEFAULT_THREAD_LIFE_MILLIS, DEFAULT_THREAD_PAUSE_MILLIS); } DefaultTaskScheduler();  DefaultTaskScheduler(int maxThreadSize);  DefaultTaskScheduler(int maxThreadSize, long threadLifeMillis, long threadPauseDelayMillis); }
DefaultTaskScheduler implements ITaskScheduler { public DefaultTaskScheduler() { this(Runtime.getRuntime().availableProcessors() * 2, DEFAULT_THREAD_LIFE_MILLIS, DEFAULT_THREAD_PAUSE_MILLIS); } DefaultTaskScheduler();  DefaultTaskScheduler(int maxThreadSize);  DefaultTaskScheduler(int maxThreadSize, long threadLifeMillis, long threadPauseDelayMillis); static long getDefaultThreadLifeMillis(); static long getDefaultThreadPauseMillis(); static AtomicInteger getGroupCount(); Deque<IScheduledTask<?>> getTaskEntries(); ThreadGroup getThreadGroup(); AtomicLong getTHREAD_COUNT(); int getMaxThreadSize(); void setMaxThreadSize(int maxThreadSize); long getThreadLifeMillis(); void setThreadLifeMillis(long threadLifeMillis); long getThreadPauseDelayMillis(); void setThreadPauseDelayMillis(long threadPauseDelayMillis); @Override int getCurrentWorkerCount(); @Override IWorkableThread createWorker(); @Override IWorkableThread hasFreeWorker(); @Override Collection<IWorkableThread> getWorkers(); @Override IScheduledTask<V> schedule(Callable<V> callable); @Override IScheduledTask<V> schedule(Callable<V> callable, long delay); @Override IScheduledTask<V> schedule(Callable<V> callable, long delay, TimeUnit timeUnit); @Override IScheduledTask<V> schedule(Callable<V> callable, long delay, long repeat); @Override IScheduledTask<V> schedule(Callable<V> callable, long delay, long repeat, TimeUnit timeUnit); @Override IScheduledTask<V> schedule(Callable<V> callable, long delay, long repeat, long repeats); @Override IScheduledTask<V> schedule(Callable<V> callable, long delay, long repeat, long repeats, TimeUnit timeUnit); @Override IScheduledTask<Void> schedule(Runnable runnable); @Override IScheduledTask<Void> schedule(Runnable runnable, long delay); @Override IScheduledTask<Void> schedule(Runnable runnable, long delay, TimeUnit timeUnit); @Override IScheduledTask<Void> schedule(Runnable runnable, long delay, long repeat); @Override IScheduledTask<Void> schedule(Runnable runnable, long delay, long repeat, TimeUnit timeUnit); @Override IScheduledTask<Void> schedule(Runnable runnable, long delay, long repeat, long repeats); @Override IScheduledTask<Void> schedule(Runnable runnable, long delay, long repeat, long repeats, TimeUnit timeUnit); @Override void shutdown(); @Override void execute(@NotNull Runnable command); @Override IScheduledTask<V> offerTask(IScheduledTask<V> scheduledTask); @Override ITaskScheduler cancelAll(); }
DefaultTaskScheduler implements ITaskScheduler { public DefaultTaskScheduler() { this(Runtime.getRuntime().availableProcessors() * 2, DEFAULT_THREAD_LIFE_MILLIS, DEFAULT_THREAD_PAUSE_MILLIS); } DefaultTaskScheduler();  DefaultTaskScheduler(int maxThreadSize);  DefaultTaskScheduler(int maxThreadSize, long threadLifeMillis, long threadPauseDelayMillis); static long getDefaultThreadLifeMillis(); static long getDefaultThreadPauseMillis(); static AtomicInteger getGroupCount(); Deque<IScheduledTask<?>> getTaskEntries(); ThreadGroup getThreadGroup(); AtomicLong getTHREAD_COUNT(); int getMaxThreadSize(); void setMaxThreadSize(int maxThreadSize); long getThreadLifeMillis(); void setThreadLifeMillis(long threadLifeMillis); long getThreadPauseDelayMillis(); void setThreadPauseDelayMillis(long threadPauseDelayMillis); @Override int getCurrentWorkerCount(); @Override IWorkableThread createWorker(); @Override IWorkableThread hasFreeWorker(); @Override Collection<IWorkableThread> getWorkers(); @Override IScheduledTask<V> schedule(Callable<V> callable); @Override IScheduledTask<V> schedule(Callable<V> callable, long delay); @Override IScheduledTask<V> schedule(Callable<V> callable, long delay, TimeUnit timeUnit); @Override IScheduledTask<V> schedule(Callable<V> callable, long delay, long repeat); @Override IScheduledTask<V> schedule(Callable<V> callable, long delay, long repeat, TimeUnit timeUnit); @Override IScheduledTask<V> schedule(Callable<V> callable, long delay, long repeat, long repeats); @Override IScheduledTask<V> schedule(Callable<V> callable, long delay, long repeat, long repeats, TimeUnit timeUnit); @Override IScheduledTask<Void> schedule(Runnable runnable); @Override IScheduledTask<Void> schedule(Runnable runnable, long delay); @Override IScheduledTask<Void> schedule(Runnable runnable, long delay, TimeUnit timeUnit); @Override IScheduledTask<Void> schedule(Runnable runnable, long delay, long repeat); @Override IScheduledTask<Void> schedule(Runnable runnable, long delay, long repeat, TimeUnit timeUnit); @Override IScheduledTask<Void> schedule(Runnable runnable, long delay, long repeat, long repeats); @Override IScheduledTask<Void> schedule(Runnable runnable, long delay, long repeat, long repeats, TimeUnit timeUnit); @Override void shutdown(); @Override void execute(@NotNull Runnable command); @Override IScheduledTask<V> offerTask(IScheduledTask<V> scheduledTask); @Override ITaskScheduler cancelAll();  }