|
|
@ -74,21 +74,21 @@ public class ThreadPoolExecutors { |
|
|
|
* @param event |
|
|
|
* @param event |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void execute(final Runnable event) { |
|
|
|
public void execute(final Runnable event) { |
|
|
|
Executor executor = getExecutor(); |
|
|
|
Executor eventExecutor = getExecutor(); |
|
|
|
if (executor == null) { |
|
|
|
if (eventExecutor == null) { |
|
|
|
logger.error("Cannot execute [" + event + "] because the executor is missing."); |
|
|
|
logger.error("Cannot execute [{}}] because the executor is missing.", event); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
executor.execute(event); |
|
|
|
eventExecutor.execute(event); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Future<?> submit(Runnable event) { |
|
|
|
public Future<?> submit(Runnable event) { |
|
|
|
Executor executor = getExecutor(); |
|
|
|
Executor eventExecutor = getExecutor(); |
|
|
|
if (executor == null) { |
|
|
|
if (eventExecutor == null) { |
|
|
|
logger.error("Cannot submit [" + event + "] because the executor is missing."); |
|
|
|
logger.error("Cannot submit [{}}] because the executor is missing.", event); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return executor.submit(event); |
|
|
|
return eventExecutor.submit(event); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return null; |
|
|
|
return null; |
|
|
@ -97,11 +97,11 @@ public class ThreadPoolExecutors { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Future<?> submit(Callable<?> task) { |
|
|
|
public Future<?> submit(Callable<?> task) { |
|
|
|
Executor executor = getExecutor(); |
|
|
|
Executor taskExecutor = getExecutor(); |
|
|
|
if (executor == null) { |
|
|
|
if (taskExecutor == null) { |
|
|
|
logger.error("Cannot submit [" + task + "] because the executor is missing."); |
|
|
|
logger.error("Cannot submit [{}] because the executor is missing.", task); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return executor.submit(task); |
|
|
|
return taskExecutor.submit(task); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return null; |
|
|
|
return null; |
|
|
@ -110,8 +110,8 @@ public class ThreadPoolExecutors { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void printStatus() { |
|
|
|
public void printStatus() { |
|
|
|
Executor executor = getExecutor(); |
|
|
|
Executor printExecutor = getExecutor(); |
|
|
|
executor.getStatus().dumpInfo(); |
|
|
|
printExecutor.getStatus().dumpInfo(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -125,7 +125,7 @@ public class ThreadPoolExecutors { |
|
|
|
List<Runnable> wasRunning = executor.threadPoolExecutor |
|
|
|
List<Runnable> wasRunning = executor.threadPoolExecutor |
|
|
|
.shutdownNow(); |
|
|
|
.shutdownNow(); |
|
|
|
if (!wasRunning.isEmpty()) { |
|
|
|
if (!wasRunning.isEmpty()) { |
|
|
|
logger.info(executor + " had " + wasRunning + " on shutdown"); |
|
|
|
logger.info("{} had {} on shutdown", executor, wasRunning); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -138,7 +138,7 @@ public class ThreadPoolExecutors { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* how long to retain excess threads |
|
|
|
* how long to retain excess threads |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
final long keepAliveTimeInMillis = 1000; |
|
|
|
static final long KEEP_ALIVE_TIME_IN_MILLIS = 1000; |
|
|
|
/** |
|
|
|
/** |
|
|
|
* the thread pool executor that services the requests |
|
|
|
* the thread pool executor that services the requests |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -146,7 +146,7 @@ public class ThreadPoolExecutors { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* work queue to use - unbounded queue |
|
|
|
* work queue to use - unbounded queue |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
final BlockingQueue<Runnable> q = new LinkedBlockingQueue<Runnable>(); |
|
|
|
final BlockingQueue<Runnable> q = new LinkedBlockingQueue<>(); |
|
|
|
private final String name; |
|
|
|
private final String name; |
|
|
|
private static final AtomicLong seqids = new AtomicLong(0); |
|
|
|
private static final AtomicLong seqids = new AtomicLong(0); |
|
|
|
private final long id; |
|
|
|
private final long id; |
|
|
@ -156,7 +156,7 @@ public class ThreadPoolExecutors { |
|
|
|
this.name = name; |
|
|
|
this.name = name; |
|
|
|
//create the thread pool executor
|
|
|
|
//create the thread pool executor
|
|
|
|
this.threadPoolExecutor = new TrackingThreadPoolExecutor( |
|
|
|
this.threadPoolExecutor = new TrackingThreadPoolExecutor( |
|
|
|
maxThreads, maxThreads, keepAliveTimeInMillis, |
|
|
|
maxThreads, maxThreads, KEEP_ALIVE_TIME_IN_MILLIS, |
|
|
|
TimeUnit.MILLISECONDS, q); |
|
|
|
TimeUnit.MILLISECONDS, q); |
|
|
|
// name the threads for this threadpool
|
|
|
|
// name the threads for this threadpool
|
|
|
|
ThreadFactoryBuilder tfb = new ThreadFactoryBuilder(); |
|
|
|
ThreadFactoryBuilder tfb = new ThreadFactoryBuilder(); |
|
|
|