主线程将数据放到一个LinkedList中,然后5个处理线程(RequestProcessor )取数据并处理。
下面这样写,好像同时只有一个RequestProcessor线程在运行,并不是5个同时运行。
请问如何修改,谢谢!import java.util.LinkedList;
import java.util.List;class RequestProcessor implements Runnable {
public int number; public RequestProcessor(int number) {
this.number = number;
} private static List pool = new LinkedList(); public static void Request(String result) {
synchronized (pool) {
pool.add(pool.size(), result);
pool.notifyAll();
}
} public void run() {
while (true) {
         String resultSet;
synchronized (pool) {
while (pool.isEmpty()) {
try {
pool.wait();
} catch (InterruptedException e) {
}
}
resultSet = (String) pool.remove(0);
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
} }
}
}}public class Test {
public static void main(String args[]) {
for (int i = 0; i < 5; i++) {
Thread t = new Thread(new RequestProcessor(i));
t.start();
}
for (int i = 0; i < 100; i++) {
String ht = String.valueOf(i);
RequestProcessor.Request(ht);
} }
}