¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.framework.manager; |
| | | |
| | | import java.util.TimerTask; |
| | | import java.util.concurrent.ScheduledExecutorService; |
| | | import java.util.concurrent.TimeUnit; |
| | | import com.ruoyi.common.utils.Threads; |
| | | import com.ruoyi.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); |
| | | } |
| | | } |