public class ScheduledKit extends Object
| 限定符和类型 | 方法和说明 |
|---|---|
static ScheduledExecutorService |
getExecutor() |
static void |
init(int corePoolSize)
初始化
|
static void |
init(ScheduledExecutorService executor)
传递 ScheduledExecutorService 对象进行初始化,从而完全掌控线程池参数
|
static <V> ScheduledFuture<V> |
schedule(Callable<V> task,
long delay,
TimeUnit unit)
创建一次性调度,在给定的 delay 时间后调度
|
static ScheduledFuture<?> |
schedule(Runnable task,
long delay,
TimeUnit unit)
创建一次性调度,在给定的 delay 时间后调度
|
static ScheduledFuture<?> |
scheduleAtFixedRate(Runnable task,
long initialDelay,
long period,
TimeUnit unit)
以固定频率执行任务
|
static ScheduledFuture<?> |
scheduleWithFixedDelay(Runnable task,
long initialDelay,
long delay,
TimeUnit unit)
以固定延迟执行任务
|
static void |
shutdown()
等待正在执行的线程执行完毕以后,关闭线程池
|
static void |
shutdownNow()
停掉正在执行的线程,关闭线程池
|
public static void init(int corePoolSize)
corePoolSize - the number of threads to keep in the pool, even if they are idlepublic static void init(ScheduledExecutorService executor)
public static ScheduledExecutorService getExecutor()
public static ScheduledFuture<?> scheduleWithFixedDelay(Runnable task, long initialDelay, long delay, TimeUnit unit)
task - 被执行的任务initialDelay - 第一次启动前的延迟delay - 上次任务 "完成" 时间与本次任务 "开始" 时间的间隔unit - 时间单位public static ScheduledFuture<?> scheduleAtFixedRate(Runnable task, long initialDelay, long period, TimeUnit unit)
task - 被执行的任务initialDelay - 第一次启动前的延迟period - 上次任务 "开始" 时间与本次任务 "开始" 时间的间隔,如果任务执行时长超出 period 值,则在任务执行完成后立即调度任务执行unit - 时间单位public static ScheduledFuture<?> schedule(Runnable task, long delay, TimeUnit unit)
task - 被执行任务delay - 从现在开始的延迟时间unit - 时间单位public static <V> ScheduledFuture<V> schedule(Callable<V> task, long delay, TimeUnit unit)
task - 被执行任务delay - 从现在开始的延迟时间unit - 时间单位public static void shutdown()
public static void shutdownNow()
Copyright © 2022. All rights reserved.