67,512
社区成员
发帖
与我相关
我的任务
分享
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class ExecutorTest extends Thread {
String name;
public ExecutorTest(String s) {
this.name = s;
}
public void run() {
try {
System.out.println(Thread.currentThread().getName() + " start....");
System.out.println(name);
// result = xxxx.get(name); 调用RMI方法
if ("3333".equals(name)) {//这里模拟调用RMI方法后获得返回值
//停止循环队列,该如何实现。
}
System.out.println(Thread.currentThread().getName() + " end...");
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String args[]) {
ExecutorService service = Executors.newFixedThreadPool(4);
Queue<String> allTasks = new ConcurrentLinkedQueue<String>();
allTasks.offer("1111");
allTasks.offer("2222");
allTasks.offer("3333");
allTasks.offer("4444");
allTasks.offer("5555");
allTasks.offer("6666");
String str;
while ((str = allTasks.poll()) != null) {
service.execute(new ExecutorTest(str));
}
System.out.println("submit finish");
service.shutdown();
}
}
写了段代码,请教下该如何根据调用RMI方法后获得返回值来处理是否继续循环队列。