設計時,需注意:安全
newSingleThreadExecutor
newFixedThreadPool
setRejectedExecutionHandler
ThreadPoolExecutor.AbortPolicy
RejectedExecutionException
ThreadPoolExecutor.CallerRunsPolicy
ThreadPoolExecutor.DiscardOldestPolicy
SynchronousQueue使用,能夠實現任務提交併等待的效果
ThreadPoolExecutor.DiscardPolicy
Semaphore
使用
newCachedThreadPool
UncaughtExceptionHandler
Executors.privilegedThreadFactory()
Executors.unconfigurableExecutorService()
beforeExecutor
afterExecutor
terminate
void execute(Runnable command)
Future submit(Callable task)
Future submit(Runnable task)
Future submit(Runnable task, T result)
List<Future> invokeAll(Collection<? extends Callable<T>> tasks)
List<Future> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
T List<Future> invokeAny(Collection<? extends Callable<T>> tasks)
T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
CompletionService
ExecutorCompletionService