From 4a33b783168846bd71eb849e1a922ae864237fbe Mon Sep 17 00:00:00 2001
From: zhubaomin <zhubaomin>
Date: 星期四, 19 九月 2024 13:51:43 +0800
Subject: [PATCH] 2024-09-19 朱宝民 获取收据列表接口增加查询条件和返回值
---
pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/threadPool/ThreadPoolImp.java | 111 +++++++++++++++++++++++++++----------------------------
1 files changed, 54 insertions(+), 57 deletions(-)
diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/threadPool/ThreadPoolImp.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/threadPool/ThreadPoolImp.java
index 204d758..ba8154a 100644
--- a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/threadPool/ThreadPoolImp.java
+++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/threadPool/ThreadPoolImp.java
@@ -73,38 +73,7 @@
/**
* 鏃ュ織
*/
- private Logger log = LogManager.getLogger(MonitorThread.class.getName());
-
- /**
- * 寰楀埌榛樿鍞竴瀹炰緥
- * @return
- */
-// public MyThreadPool getDefaultInstance(){
-// if(myPool == null){
-// myPool = new MyThreadPool(null, null, null, null, null) ;
-// }
-// return myPool ;
-// }
- /**
- * 寰楀埌鍞竴瀹炰緥
- * @param poolName
- * @param maxNum
- * @param minNum
- * @param freeTimeout
- * @param busyTimeout
- * @return
- */
-// public MyThreadPool getInstance(
-// String poolName ,
-// Integer maxNum ,
-// Integer minNum ,
-// Long freeTimeout ,
-// Long busyTimeout){
-// if(myPool == null){
-// myPool = new MyThreadPool(poolName, maxNum, minNum, freeTimeout, busyTimeout) ;
-// }
-// return myPool ;
-// }
+ private static final Logger log = LogManager.getLogger(MonitorThread.class) ;
/**
* 绾跨▼姹犳瀯閫犳柟娉�
@@ -125,8 +94,8 @@
}
this.poolName = poolName ;
- if(maxNum == null || maxNum.intValue() <= 0){
- maxNum = -1 ;
+ if(maxNum == null || maxNum.intValue() < 0){
+ maxNum = 65535 ;
}
if(minNum == null || minNum.intValue() < 0){
minNum = 0 ;
@@ -148,20 +117,35 @@
}else{
this.busyTimeout = busyTimeout ;
}
-
- this.busiThreads = new ArrayList<MyThread>();
- this.freeThreads = new ArrayList<MyThread>();
-
- //鏈�灏忓寲绾跨▼姹�
- for (int i = 0; i < this.minNum ; i++) {
- MyThread t = new MyThread(this);
- t.start();
- this.freeThreads.add(t);
- this.currNum++;
+ if(maxNum != 0){
+ this.busiThreads = new ArrayList<>();
+ this.freeThreads = new ArrayList<>();
+ //鏈�灏忓寲绾跨▼姹�
+ for (int i = 0; i < this.minNum ; i++) {
+ MyThread t = new MyThread(this);
+ t.start();
+ this.freeThreads.add(t);
+ this.currNum++;
+ }
+ this.monitorThread = new MonitorThread(this) ;
+ this.monitorThread.start() ;
}
-
- this.monitorThread = new MonitorThread(this) ;
- this.monitorThread.start() ;
+ }
+ /**
+ * 绾跨▼姹犱腑绾跨▼涓暟
+ * @return
+ */
+ @Override
+ public Integer size() {
+ return currNum ;
+ }
+ @Override
+ public Integer maxThread() {
+ return maxNum ;
+ }
+ @Override
+ public Integer minThread() {
+ return minNum ;
}
/**
@@ -171,6 +155,9 @@
*/
@Override
public void putJob(Job job) throws Exception {
+ if(this.busiThreads == null || this.freeThreads == null){
+ throw new Exception("绾跨▼姹犳湭鍚姩") ;
+ }
synchronized(this.synObj) {
//log.debug("宸ヤ綔浠诲姟鍒嗛厤鍒扮嚎绋嬫睜涓��") ;
MyThread t = null ;
@@ -215,7 +202,10 @@
/**
* 绾跨▼宸ヤ綔瀹屾垚锛屼粠busiThreads鍥炲綊freeThreads
*/
- protected void freeThread(MyThread t) {
+ protected void freeThread(MyThread t) throws Exception {
+ if(this.busiThreads == null || this.freeThreads == null){
+ throw new Exception("绾跨▼姹犳湭鍚姩") ;
+ }
synchronized (synObj) {
busiThreads.remove(t);
freeThreads.add(t);
@@ -236,7 +226,7 @@
/**
*
- * @param pool
+ * @param pool 姹�
*/
public MonitorThread(MyThreadPool pool){
this.pool = pool ;
@@ -302,6 +292,7 @@
}
}//end synchronized (pool.synObj)
}catch(Exception e){
+ e.printStackTrace();
}finally{
continue ;
}
@@ -354,7 +345,7 @@
/**
* 璁剧疆绾跨▼宸ヤ綔瀵硅薄
- * @param job
+ * @param job 宸ヤ綔
*/
protected void putJob(Job job) throws Exception {
if(job == null){
@@ -418,13 +409,19 @@
}
public void free(){
- //浣挎湰绾跨▼鍥炲綊绌洪棽绾跨▼姹�
- pool.freeThread(this);
- //绌洪棽寮�濮嬭鏃�
- this.time = System.currentTimeMillis() ;
- // 娌℃湁鍙仛鐨勪簡
- this.canJob = false;
- log.debug("绾跨▼姹�(" + this.pool.poolName + ")涓殑绾跨▼鍥炲綊绌洪棽闆嗗悎銆�");
+ try{
+ //浣挎湰绾跨▼鍥炲綊绌洪棽绾跨▼姹�
+ pool.freeThread(this);
+ //绌洪棽寮�濮嬭鏃�
+ this.time = System.currentTimeMillis() ;
+ // 娌℃湁鍙仛鐨勪簡
+ this.canJob = false;
+ log.debug("绾跨▼姹�(" + this.pool.poolName + ")涓殑绾跨▼鍥炲綊绌洪棽闆嗗悎銆�");
+ }catch (Exception e){
+ log.error("绾跨▼姹�(" + pool.poolName + ")鐨勫伐浣滅嚎绋嬮噴鏀惧洖褰掓椂鍙戠敓寮傚父:\n" + e.getMessage(), e);
+ e.printStackTrace();
+ }
+
}
/**
--
Gitblit v1.8.0