From 3c4fee1db116c11d4f04727cfe076d7c94daeaf2 Mon Sep 17 00:00:00 2001 From: yanzhaofeige <yanzhaofeige@qq.com> Date: Mon, 30 Sep 2024 12:10:57 +0800 Subject: [PATCH] init --- cpzidc-framework/src/main/java/com/odcc/cpzidc/framework/manager/AsyncManager.java | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 55 insertions(+), 0 deletions(-) diff --git a/cpzidc-framework/src/main/java/com/odcc/cpzidc/framework/manager/AsyncManager.java b/cpzidc-framework/src/main/java/com/odcc/cpzidc/framework/manager/AsyncManager.java new file mode 100644 index 0000000..d7bde3f --- /dev/null +++ b/cpzidc-framework/src/main/java/com/odcc/cpzidc/framework/manager/AsyncManager.java @@ -0,0 +1,55 @@ +package com.odcc.cpzidc.framework.manager; + +import java.util.TimerTask; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; +import com.odcc.cpzidc.common.utils.Threads; +import com.odcc.cpzidc.common.utils.spring.SpringUtils; + +/** + * 异步任务管理器 + * + * @author ruoyi + */ +public class AsyncManager +{ + /** + * 操作延迟10毫秒 + */ + private final int OPERATE_DELAY_TIME = 10; + + /** + * 异步操作任务调度线程池 + */ + private ScheduledExecutorService executor = SpringUtils.getBean("scheduledExecutorService"); + + /** + * 单例模式 + */ + private AsyncManager(){} + + private static AsyncManager me = new AsyncManager(); + + public static AsyncManager me() + { + return me; + } + + /** + * 执行任务 + * + * @param task 任务 + */ + public void execute(TimerTask task) + { + executor.schedule(task, OPERATE_DELAY_TIME, TimeUnit.MILLISECONDS); + } + + /** + * 停止任务线程池 + */ + public void shutdown() + { + Threads.shutdownAndAwaitTermination(executor); + } +} -- Gitblit v1.9.3