该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
缓存队列:
public class TaskPool {
//任务计数
private int size;
//最大线程数
private int maxCount;
//剩余线程数
private int surCount;
//初始化线程数
private int max_count;
//最长等待时间
private int waitTime;
//当前持有的额外线程数
private int holdNum;
//任务列表
public final static ArrayBlockingQueue blockqueue=new ArrayBlockingQueue(100);
//将信息打印到控制台
private static Logger log = Logger.getLogger("CONSOLE");
//添加任务
public void add(Task task){
try {
blockqueue.put(task);
} catch (InterruptedException e) {
log.debug("加入任务出错");
}
synchronized (TaskPool.class) {
size++;
if(surCount>0){
TaskPool.class.notify();
surCount--;
}else if(holdNum
new Thread(new AssistRun(this)).start();
holdNum++;
}
}
}
//启动线程池
public void start(){
surCount=max_count;
for (int i = 0; i < maxCount; i++) {
new Thread(new WorkThread(this)).start();
surCount--;
}
}
//销毁线程池
public void destroy(){
System.err.println("销毁其线程池");
}
public synchronized void setMaxCount(int maxCount){
this.maxCount=maxCount;
}
public int getMaxCount(){
return this.maxCount;
}
public int getSurCount(){
return this.surCount;
}
public synchronized void setSurCount(int surCount){
this.surCount=surCount;
}
public int getSize(){
return size++;
}
public synchronized void setSize(int size){
this.size=size;
}
public int getMax_count() {
return max_count;
}
public synchronized void setMax_count(int max_count) {
this.max_count = max_count;
}
public int getWaitTime() {
return waitTime;
}
public synchronized void setWaitTime(int waitTime) {
this.waitTime = waitTime;
}
public int getHoldNum() {
return holdNum;
}
public synchronized void setHoldNum(int holdNum) {
this.holdNum = holdNum;
}
}