mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix schedule bug
This commit is contained in:
parent
6b073a5788
commit
5697b4b7b0
@ -10,6 +10,7 @@
|
||||
* 【core 】 NumberUtil增加方法decimalFormat重载(issue#I3OSA2@Gitee)
|
||||
* 【extra 】 Ftp的remoteVerificationEnabled改为false(issue#I3OSA2@Gitee)
|
||||
### 🐞Bug修复
|
||||
* 【core 】 修复createScheduledExecutor单位不是毫秒的问题(issue#I3OYIW@Gitee)
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
@ -553,6 +553,32 @@ public class ThreadUtil {
|
||||
return new ScheduledThreadPoolExecutor(corePoolSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始执行一个定时任务,执行方式分fixedRate模式和fixedDelay模式。<br>
|
||||
* 注意:此方法的延迟和周期的单位均为毫秒。
|
||||
*
|
||||
* <ul>
|
||||
* <li>fixedRate 模式:下一次任务等待上一次任务执行完毕后再启动。</li>
|
||||
* <li>fixedDelay模式:下一次任务不等待上一次任务,到周期自动执行。</li>
|
||||
* </ul>
|
||||
*
|
||||
*
|
||||
* @param executor 定时任务线程池,{@code null}新建一个默认线程池
|
||||
* @param command 需要定时执行的逻辑
|
||||
* @param initialDelay 初始延迟,单位毫秒
|
||||
* @param period 执行周期,单位毫秒
|
||||
* @param fixedRateOrFixedDelay {@code true}表示fixedRate模式,{@code false}表示fixedDelay模式
|
||||
* @return {@link ScheduledThreadPoolExecutor}
|
||||
* @since 5.5.8
|
||||
*/
|
||||
public static ScheduledThreadPoolExecutor schedule(ScheduledThreadPoolExecutor executor,
|
||||
Runnable command,
|
||||
long initialDelay,
|
||||
long period,
|
||||
boolean fixedRateOrFixedDelay){
|
||||
return schedule(executor, command, initialDelay, period, TimeUnit.MILLISECONDS, fixedRateOrFixedDelay);
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始执行一个定时任务,执行方式分fixedRate模式和fixedDelay模式。
|
||||
*
|
||||
@ -565,23 +591,25 @@ public class ThreadUtil {
|
||||
* @param executor 定时任务线程池,{@code null}新建一个默认线程池
|
||||
* @param command 需要定时执行的逻辑
|
||||
* @param initialDelay 初始延迟
|
||||
* @param period 执行周期,单位毫秒
|
||||
* @param period 执行周期
|
||||
* @param timeUnit 时间单位
|
||||
* @param fixedRateOrFixedDelay {@code true}表示fixedRate模式,{@code false}表示fixedDelay模式
|
||||
* @return {@link ScheduledThreadPoolExecutor}
|
||||
* @since 5.5.8
|
||||
* @since 5.6.5
|
||||
*/
|
||||
public static ScheduledThreadPoolExecutor schedule(ScheduledThreadPoolExecutor executor,
|
||||
Runnable command,
|
||||
long initialDelay,
|
||||
long period,
|
||||
boolean fixedRateOrFixedDelay){
|
||||
Runnable command,
|
||||
long initialDelay,
|
||||
long period,
|
||||
TimeUnit timeUnit,
|
||||
boolean fixedRateOrFixedDelay){
|
||||
if(null == executor){
|
||||
executor = createScheduledExecutor(2);
|
||||
}
|
||||
if(fixedRateOrFixedDelay){
|
||||
executor.scheduleAtFixedRate(command, initialDelay, period, TimeUnit.NANOSECONDS);
|
||||
executor.scheduleAtFixedRate(command, initialDelay, period, timeUnit);
|
||||
} else{
|
||||
executor.scheduleWithFixedDelay(command, initialDelay, period, TimeUnit.NANOSECONDS);
|
||||
executor.scheduleWithFixedDelay(command, initialDelay, period, timeUnit);
|
||||
}
|
||||
|
||||
return executor;
|
||||
|
Loading…
x
Reference in New Issue
Block a user