public class ThreadPool extends Object
| Modifier and Type | Field and Description |
|---|---|
private static org.slf4j.Logger |
log |
private static int |
SHUT_TIME |
private static ThreadPoolExecutor |
SINGLE_THREAD_POOL
创建线程池 普通线程池
|
private static ExecutorService |
TTL_SERVICE
多线程下可以获取用户信息的 线程池
|
| Modifier | Constructor and Description |
|---|---|
private |
ThreadPool() |
| Modifier and Type | Method and Description |
|---|---|
static void |
execute(Runnable runnable) |
static void |
printException(Runnable r,
Throwable t)
打印线程异常信息
|
static ScheduledFuture<?> |
scheduleAtFixedRate(ScheduledThreadPoolExecutor executor,
Runnable command,
Duration initialDelay,
Duration period)
执行延迟任务 任务执行时间超过间隔时间的 直接执行
|
static ScheduledThreadPoolExecutor |
scheduledThread(String poolName)
创建一个 延迟线程池
|
static ScheduledFuture<?> |
scheduleWithFixedDelay(ScheduledThreadPoolExecutor executor,
Runnable command,
Duration initialDelay,
Duration delay)
执行延迟任务 下次任务开始时间以上次任务结束时间开始 加上延迟的间隔时间
|
static void |
shutdownAndAwaitTermination()
停止线程池
先使用shutdown, 停止接收新任务并尝试完成所有已存在任务.
|
static void |
shutdownAndAwaitTermination(ExecutorService pool)
停止线程池
先使用shutdown, 停止接收新任务并尝试完成所有已存在任务.
|
static void |
submit(Runnable runnable) |
static void |
ttlExecute(Runnable r)
可以在子线程里面获取到用户信息
|
private static final int SHUT_TIME
private static final org.slf4j.Logger log
private static final ExecutorService TTL_SERVICE
private static final ThreadPoolExecutor SINGLE_THREAD_POOL
public static void submit(Runnable runnable)
public static void execute(Runnable runnable)
public static void ttlExecute(Runnable r)
r - 线程方法public static void shutdownAndAwaitTermination()
public static void shutdownAndAwaitTermination(ExecutorService pool)
public static ScheduledThreadPoolExecutor scheduledThread(String poolName)
poolName - 名称public static ScheduledFuture<?> scheduleWithFixedDelay(ScheduledThreadPoolExecutor executor, Runnable command, Duration initialDelay, Duration delay)
executor - 线程池command - 任务initialDelay - 延迟时间 秒delay - 延迟间隔时间public static ScheduledFuture<?> scheduleAtFixedRate(ScheduledThreadPoolExecutor executor, Runnable command, Duration initialDelay, Duration period)
executor - 线程池command - 任务initialDelay - 延迟时间period - 间隔时间Copyright © 2024. All rights reserved.