ExecutorService pool=Executors.newFixedThreadPool(2);
Future<Integer> f1=pool.submit(new MyCallable(100));
Integer i =f1.get();
syso(i);
class MyCallable extends Callable{
private Integer i;
int sum=0;
public Callable(Integer i){
this.i=i;
}
public int call() throws exception{
for(int x=0;x<=i;x++){
sum+=i;
}
return sum;
}
添加回答
举报
0/150
提交
取消