mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
add method
This commit is contained in:
parent
7693bc131e
commit
028c3ed60d
@ -12,6 +12,7 @@ import java.util.concurrent.ScheduledThreadPoolExecutor;
|
|||||||
import java.util.concurrent.ThreadFactory;
|
import java.util.concurrent.ThreadFactory;
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 线程池工具
|
* 线程池工具
|
||||||
@ -366,6 +367,19 @@ public class ThreadUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建本地线程对象
|
||||||
|
*
|
||||||
|
* @param <T> 持有对象类型
|
||||||
|
* @param supplier 初始化线程对象函数
|
||||||
|
* @return 本地线程
|
||||||
|
* @see ThreadLocal#withInitial(Supplier)
|
||||||
|
* @since 5.6.7
|
||||||
|
*/
|
||||||
|
public static <T> ThreadLocal<T> createThreadLocal(Supplier<? extends T> supplier) {
|
||||||
|
return ThreadLocal.withInitial(supplier);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建ThreadFactoryBuilder
|
* 创建ThreadFactoryBuilder
|
||||||
*
|
*
|
||||||
@ -562,7 +576,6 @@ public class ThreadUtil {
|
|||||||
* <li>fixedDelay模式:下一次任务不等待上一次任务,到周期自动执行。</li>
|
* <li>fixedDelay模式:下一次任务不等待上一次任务,到周期自动执行。</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
*
|
|
||||||
* @param executor 定时任务线程池,{@code null}新建一个默认线程池
|
* @param executor 定时任务线程池,{@code null}新建一个默认线程池
|
||||||
* @param command 需要定时执行的逻辑
|
* @param command 需要定时执行的逻辑
|
||||||
* @param initialDelay 初始延迟,单位毫秒
|
* @param initialDelay 初始延迟,单位毫秒
|
||||||
@ -575,7 +588,7 @@ public class ThreadUtil {
|
|||||||
Runnable command,
|
Runnable command,
|
||||||
long initialDelay,
|
long initialDelay,
|
||||||
long period,
|
long period,
|
||||||
boolean fixedRateOrFixedDelay){
|
boolean fixedRateOrFixedDelay) {
|
||||||
return schedule(executor, command, initialDelay, period, TimeUnit.MILLISECONDS, fixedRateOrFixedDelay);
|
return schedule(executor, command, initialDelay, period, TimeUnit.MILLISECONDS, fixedRateOrFixedDelay);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -587,7 +600,6 @@ public class ThreadUtil {
|
|||||||
* <li>fixedDelay模式:下一次任务不等待上一次任务,到周期自动执行。</li>
|
* <li>fixedDelay模式:下一次任务不等待上一次任务,到周期自动执行。</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
*
|
|
||||||
* @param executor 定时任务线程池,{@code null}新建一个默认线程池
|
* @param executor 定时任务线程池,{@code null}新建一个默认线程池
|
||||||
* @param command 需要定时执行的逻辑
|
* @param command 需要定时执行的逻辑
|
||||||
* @param initialDelay 初始延迟
|
* @param initialDelay 初始延迟
|
||||||
@ -602,13 +614,13 @@ public class ThreadUtil {
|
|||||||
long initialDelay,
|
long initialDelay,
|
||||||
long period,
|
long period,
|
||||||
TimeUnit timeUnit,
|
TimeUnit timeUnit,
|
||||||
boolean fixedRateOrFixedDelay){
|
boolean fixedRateOrFixedDelay) {
|
||||||
if(null == executor){
|
if (null == executor) {
|
||||||
executor = createScheduledExecutor(2);
|
executor = createScheduledExecutor(2);
|
||||||
}
|
}
|
||||||
if(fixedRateOrFixedDelay){
|
if (fixedRateOrFixedDelay) {
|
||||||
executor.scheduleAtFixedRate(command, initialDelay, period, timeUnit);
|
executor.scheduleAtFixedRate(command, initialDelay, period, timeUnit);
|
||||||
} else{
|
} else {
|
||||||
executor.scheduleWithFixedDelay(command, initialDelay, period, timeUnit);
|
executor.scheduleWithFixedDelay(command, initialDelay, period, timeUnit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user