From 1a2b07f01ba4616fd9e894dddf474b56d020158c Mon Sep 17 00:00:00 2001
From: zhubaomin <zhubaomin>
Date: 星期一, 07 四月 2025 15:18:51 +0800
Subject: [PATCH] 整理版本

---
 pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/core/CoreTimer.java |   80 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 80 insertions(+), 0 deletions(-)

diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/core/CoreTimer.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/core/CoreTimer.java
new file mode 100644
index 0000000..9e30fd6
--- /dev/null
+++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/core/CoreTimer.java
@@ -0,0 +1,80 @@
+package com.dy.common.mw.core;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.util.Timer;
+import java.util.TimerTask;
+
+/**
+ * @Author: liurunyu
+ * @Date: 2024/11/21 13:41
+ * @Description
+ */
+public class CoreTimer extends TimerTask {
+
+    private static final Logger log = LogManager.getLogger(CoreTimer.class.getName()) ;
+
+    private static final CoreTimer instance = new CoreTimer() ;
+
+    private Long workInterval = 100L ;//鏍稿績绾跨▼鏆傚仠闂撮殧
+
+    private Timer timer;
+
+    private boolean stop;
+
+    private CoreTimer(){
+        this.timer = new Timer();
+        this.stop = false ;
+    }
+
+    public static CoreTimer getInstance(){
+        return instance ;
+    }
+
+    public void stop(){
+        this.stop = true ;
+        if(this.timer != null){
+            this.timer.cancel();
+        }
+    }
+    public boolean isStop(){
+        return this.stop ;
+    }
+
+    /**
+     * 璁剧疆/鏍稿績绾跨▼鏆傚仠闂撮殧
+     * @param workInterval /鏍稿績绾跨▼鏆傚仠闂撮殧
+     */
+    public void setSleep(Long workInterval){
+        this.workInterval = workInterval ;
+    }
+
+    public void start(){
+        this.timer.schedule(this, 0 , this.workInterval);
+    }
+
+    /**
+     * TimerTask鐨剅un鏂规硶
+     */
+    @Override
+    public void run() {
+        try{
+            /**
+             * 姝ゅ鍙栧嚭褰撳墠闃熷垪鐨勮妭鐐规暟閲忥紝浣滀负涓�涓畾閲廲ount澶勭悊锛�
+             * 鍘熷洜:
+             * 鍦ㄥ鐞嗗畾閲廲ount杩囩▼涓紝鍙兘鏈夌殑鑺傜偣鍙堝洖鍒伴槦鍒椾腑锛屼篃鍙兘鏂扮敓鑺傜偣杩涘叆闃熷垪涓紝鍗冲湪澶勭悊杩囩▼涓紝闃熷垪鍙兘鍙堝闀夸簡
+             */
+            int count = CoreUnit.taskQueue.size() ;
+            while(count > 0){
+                CoreTask task = (CoreTask)CoreUnit.taskQueue.pop() ;
+                if(task != null){
+                    task.execute();
+                }
+                count-- ;
+            }
+        }catch(Exception e){
+            log.error("鏍稿績绾跨▼鍙戠敓寮傚父" + (e.getMessage() == null ? "" : (":" + e.getMessage())), e);;
+        }
+    }
+}

--
Gitblit v1.8.0