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