throw new JDOMException();
}
}
public static ConsumeThreadPoolPara getConsumeThreadPoolPara(){
if(consumeThreadPoolPara ==null){
try {
Element root = loadDocument();
Element consumeThreadPool = root.getChild("ConsumeThreadPool");
if (consumeThreadPool != null) { //代表有数据库配置
consumeThreadPoolPara = new ConsumeThreadPoolPara();
Element minPools = consumeThreadPool.getChild("minPools");
consumeThreadPoolPara.setMinPools(Integer.parseInt(minPools.getTextTrim()));
Element maxPools = consumeThreadPool.getChild("maxPools");
consumeThreadPoolPara.setMaxPools(Integer.parseInt(maxPools.getTextTrim()));
Element checkThreadPeriod = consumeThreadPool.getChild("checkThreadPeriod");
consumeThreadPoolPara.setCheckThreadPeriod(Integer.parseInt(checkThreadPeriod.getTextTrim()));
}
}
catch (JDOMException e) {
}
}
return consumeThreadPoolPara;
}
}
四、线程池源代码:
import java.util.*;
/**
* <p>Title: 线程池</p>
* <p>Description: 采集消费模块</p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author 张荣斌
* @version 1.0
*/
public class ThreadPool {
private static int minPools = 10; //最小连接池数目
private static int maxPools = 100; //最大连接池数目
private static int checkThreadPeriod = 5; //检查连接池的周期
ArrayList m_ThreadList; //工作线程列表
LinkedList m_RunList = null; //工作任务列表
int totalThread = 0; //总线程数
static int freeThreadCount = 0; //未被使用的线程数目
private java.util.Timer timer = null; //定时器
static Object o = new Object();
static{ //先初始化线程池的参数
ConsumeThreadPoolPara consumeThreadPoolPara = ParseConfig.getConsumeThreadPoolPara();
if(consumeThreadPoolPara!=null){
minPools = consumeThreadPoolPara.getMinPools();
maxPools = consumeThreadPoolPara.getMaxPools();
checkThreadPeriod = consumeThreadPoolPara.getCheckThreadPeriod()*60*1000;
}
}
public void setMinPools(int minPools){
this.minPools = minPools;






