public static void main(String[] args) throws InterruptedException, ExecutionException {
ExecutorService pool = Executors.newFixedThreadPool(5);
List<Future> list = new ArrayList<Future>();
for(int i=0;i<5;++i){
Callable c = new MyCallable("任务"+i);
Future<String> f = pool.submit(c);
list.add(f);
}
for(Future f : list){
String s = (String) f.get();
System.out.println(s);
}
pool.shutdown();
}
static class MyCallable implements Callable{
private String oid;
MyCallable(String oid) {
this.oid = oid;
}
@Override
public Object call() throws Exception {
long t = (long) (Math.random()*500);
for(int i=1;i<t;++i){
System.out.println(oid+" : "+i);
}
return oid+"任务返回的内容"+t;
}