📄 threadpool.java
字号:
/*
* Created on 2005-9-2
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package com.apollo.thread.example;
import java.util.LinkedList;
public class ThreadPool {
private LinkedList list = new LinkedList();
private final int MAX_SIZE;
public ThreadPool(int size) {
this.MAX_SIZE = size;
for (int i = 0; i < size; i++) {
Thread t = new NodeProcessThread();
list.add(t);
}
}
public boolean isEmpty(){
return list.size() == 0;
}
public boolean isFull(){
return list.size() == this.MAX_SIZE;
}
public void push(NodeProcessThread npt){
if ( isFull() ) {
//应该抛一个“线程池满”的异常
} else {
list.add(npt);
}
}
public NodeProcessThread pop(){
NodeProcessThread result = null;
if ( isEmpty() ) {
//应该抛一个“线程池空”的异常
} else {
result = (NodeProcessThread)list.removeFirst();
}
return result;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -