public final class WuicScheduledThreadPool extends Thread
This class is used internally by WUIC to control the number of created threads for different tasks. When a peace of code needs to create asynchronous task in WUIC, it always uses this singleton which wraps a thread pool. The class is tread safe and don't need to be called with a mutex.
The singleton adds a hook with Runtime.addShutdownHook(Thread)
to shutdown the pool when executed.
Modifier and Type | Class and Description |
---|---|
static class |
WuicScheduledThreadPool.CallExceptionLogger<T>
Logs any exception which occurs when running a delegated
Callable . |
Thread.State, Thread.UncaughtExceptionHandler
Modifier and Type | Field and Description |
---|---|
static int |
POOL_SIZE
We just create 1 thread per processor.
|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
Modifier and Type | Method and Description |
---|---|
<T> Future<T> |
executeAsap(Callable<T> job)
Executes as soon as possible the given job and returns the related
Future . |
Future<?> |
executeAsap(Runnable job)
Executes as soon as possible the given job and returns the related
Future . |
ScheduledFuture<?> |
executeEveryTimeInSeconds(Runnable job,
int delay)
Schedules an execution in a specified delay of a given job.
|
static WuicScheduledThreadPool |
getInstance()
Gets the unique instance.
|
void |
run() |
void |
shutdown()
Stops the pool.
|
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
public static WuicScheduledThreadPool getInstance()
Gets the unique instance.
public ScheduledFuture<?> executeEveryTimeInSeconds(Runnable job, int delay)
Schedules an execution in a specified delay of a given job. Once the job is executed, its execution will be repeated in the initial delay, and so on.
job
- the job to executedelay
- the delay between executionspublic <T> Future<T> executeAsap(Callable<T> job)
Executes as soon as possible the given job and returns the related Future
.
job
- the job to executepublic Future<?> executeAsap(Runnable job)
Executes as soon as possible the given job and returns the related Future
.
job
- the job to executepublic void shutdown()
Stops the pool.
Copyright © 2012-2015. All Rights Reserved.