| | |
| | | import java.util.concurrent.ScheduledExecutorService; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | /** |
| | | * 异步帮助类 |
| | | * @author WWW |
| | | * @date 2023-07-10 |
| | | */ |
| | | @SuppressWarnings("ALL") |
| | | public class AsyncHelper { |
| | | /** |
| | | * 操作延迟10毫秒 |
| | | */ |
| | | private final static int OPERATE_DELAY_TIME = 10; |
| | | |
| | | // private final static AsyncHelper INSTANCE = new AsyncHelper(); |
| | |
| | | public AsyncHelper() { |
| | | } |
| | | |
| | | /** |
| | | * 执行任务 |
| | | */ |
| | | public void execute(TimerTask task) { |
| | | executor.schedule(task, OPERATE_DELAY_TIME, TimeUnit.MILLISECONDS); |
| | | } |
| | | |
| | | /** |
| | | * 关闭任务 |
| | | */ |
| | | public void shutdown() { |
| | | shutdownAndAwaitTermination(executor); |
| | | } |
| | | |
| | | /** |
| | | * 停止任务线程池 |
| | | */ |
| | | public static void shutdownAndAwaitTermination(ExecutorService pool) { |
| | | try { |
| | | if (null == pool || pool.isShutdown()) { |