From d20d38e22b06559d758c568769017e2acf632583 Mon Sep 17 00:00:00 2001
From: zuoxiao <470321431@qq.com>
Date: 星期三, 23 四月 2025 14:06:48 +0800
Subject: [PATCH] Merge branch 'master' of http://8.140.179.55:20000/r/pipIrr-SV
---
pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/core/CoreThread.java | 81 ++++++++++++++++++++++++++++++++++++++++
1 files changed, 81 insertions(+), 0 deletions(-)
diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/core/CoreThread.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/core/CoreThread.java
new file mode 100644
index 0000000..e77a8d1
--- /dev/null
+++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/core/CoreThread.java
@@ -0,0 +1,81 @@
+package com.dy.common.mw.core;
+
+import org.apache.logging.log4j.*;
+
+import com.dy.common.queue.Queue;
+
+/**
+ * 2024-11-21 璇ョ被宸茬粡寮冪敤锛屾敼鐢盋oreTimer瀹炵幇銆�
+ * 褰撻噰鐢═hread瀹炵幇鏃讹紝鍦╳hile(true){}涓娇鐢═hread.sleep()锛屽彲鑳藉鑷寸殑涓ラ噸鎬ц兘闂锛屼笉鎺ㄨ崘鍦ㄥ惊鐜腑浣跨敤绾跨▼浼戠湢銆�
+ * Java绾跨▼瀹炵幇閲囩敤鍐呮牳绾跨▼瀹炵幇锛岀嚎绋嬬殑浼戠湢鍙婂敜閱掞紙鐘舵�佸垏鎹級闇�鍊熷姪鎿嶄綔绯荤粺杩涜锛岃繖鏄竴涓瀬鍏惰�楁椂鑰楀姏鐨勬搷浣溿��
+ * 鍦ㄧ嚎绋嬩紤鐪犳垨杩愯鏃堕棿杈冮暱鐨勬儏鏅笅锛屽叾瀵规�ц兘鐨勫奖鍝嶈繕涓嶇畻鏄庢樉锛屽洜涓哄绾跨▼鐘舵�佺殑鍒囨崲骞朵笉棰戠箒銆�
+ * 浣嗚嫢绾跨▼浼戠湢鍙婅繍琛岀殑鏃堕棿閮藉緢鐭紙渚嬪姣/绉掞級锛�
+ * 绯荤粺灏嗛绻佺殑瀵圭嚎绋嬬姸鎬佽繘琛屽垏鎹紝瀵艰嚧涓ラ噸鐨勬�ц兘鎹熻�楋紝骞跺鐫�寰幆娆℃暟鐨勯�掑鑰屾斁澶с��
+ */
+@Deprecated
+public class CoreThread extends Thread{
+
+ private static Logger log = LogManager.getLogger(CoreThread.class.getName()) ;
+
+ private static CoreThread instance = new CoreThread() ;
+
+ private static Long sleepBigBusy = 100L ;//澶у繖鏃讹紙闄や簡鎭掍箙浠诲姟锛岃繕鏄叾浠栦换鍔★級锛屾牳蹇冪嚎绋嬫殏鍋滈棿闅�
+ private static Long sleepSmallBusy = 500L ;//灏忓繖鏃讹紙鍙湁鎭掍箙浠诲姟锛屾棤鍏朵粬浠诲姟锛夛紝鏍稿績绾跨▼鏆傚仠闂撮殧
+
+ private CoreThread(){
+ }
+
+ public static CoreThread getInstance(){
+ return instance ;
+ }
+
+ /**
+ * 璁剧疆鏆傚仠鏃堕暱
+ * @param sleepBigBusy 澶у繖鏃剁潯鐪犳椂闀�
+ * @param sleepSmallBusy 灏忓繖鏃剁潯鐪犳椂闀�
+ */
+ public void setSleep(Long sleepBigBusy, Long sleepSmallBusy){
+ CoreThread.sleepBigBusy = sleepBigBusy ;
+ CoreThread.sleepSmallBusy = sleepSmallBusy ;
+ }
+
+ /**
+ * 鏍稿績鍗曠嚎绋嬶紝鎵ц鎵�鏈夌殑鍗曠嚎绋嬩换鍔�
+ */
+ @SuppressWarnings("finally")
+ @Override
+ public void run() {
+ Queue coreQueue = CoreUnit.taskQueue ;
+ int count = 0 ;
+ int n = 0 ;
+ while(true){
+ try{
+ /**
+ * 姝ゅ鍙栧嚭褰撳墠闃熷垪鐨勮妭鐐规暟閲忥紝浣滀负涓�涓畾閲廲ount澶勭悊锛�
+ * 鍘熷洜:
+ * 鍦ㄥ鐞嗗畾閲廲ount杩囩▼涓紝鍙兘鏈夌殑鑺傜偣鍙堝洖鍒伴槦鍒椾腑锛屽彲鑳芥柊鐢熻妭鐐硅繘鍏ラ槦鍒椾腑锛屽嵆鍦ㄥ鐞嗚繃绋嬩腑锛岄槦鍒楀彲鑳藉張澧為暱浜�
+ */
+ count = coreQueue.size() ;
+ if(count > 0){
+ n = 0 ;
+ while(n < count){
+ CoreTask task = (CoreTask)coreQueue.pop() ;
+ if(task != null){
+ task.execute();
+ }
+ n ++ ;
+ }
+ //澶ф殏鍋滀竴涓�
+ sleep(sleepBigBusy) ;
+ }else{
+ //灏忔殏鍋滀竴涓�
+ sleep(sleepSmallBusy) ;
+ }
+ }catch(Exception e){
+ log.error("鏍稿績绾跨▼鍙戠敓寮傚父" + (e.getMessage() == null ? "" : (":" + e.getMessage())), e);;
+ }finally{
+ continue ;
+ }
+ }
+ }
+}
--
Gitblit v1.8.0