需要处理图片,感觉变化不是太大 有时候很明显 从 3000多 降到300多,而且未用线程池之前的方法执行 有时候也是几十ms,有时候就差了十几ms,也是醉了,不知道是不是使用错误
求指导。。。
public class TestCall<T> implements Callable<T>{
/**
* @param args
*/
private int id;
private static ExecutorService pool = Executors.newCachedThreadPool();
public TestCall(int i) {
this.id = i ;
}
public static void main(String[] args) throws InterruptedException, ExecutionException {
List<Future<String[]>> results = new ArrayList<Future<String[]>>();
for(int i=0;i<10;i++){
results.add(pool.submit(new TestCall(i)));
}
for (Future<String[]> fs : results) {
int k=0;
while(!fs.isDone()){
System.out.println("等待.............."+k);
Thread.sleep(1);
k++;
if(k==10){
System.out.println("不等了.............."+k);
break;
}
}
if (fs.isDone()) {
// 这里的get方法,会将String的结果拿到。
System.out.println("结束"+fs.get());
}else{
System.out.println("任务未结束:");//+fs.get());
}
}
// TODO Auto-generated method stub
// String[] widthAndh = {"这个","是","",""};
// String[] widthAndHeigth = {"","","",""};
// widthAndHeigth = widthAndh ;
// widthAndHeigth[2]= Integer.toString(3);
// widthAndHeigth[3]= "四级联考";
// String s = "null";
// s.isEmpty();
// System.out.println("是空?"+s.isEmpty());
// for(int j=0;j<4;j++){
//
// System.out.println(widthAndHeigth[j]);
// }
}
@Override
public T call() throws Exception {
if(Thread.currentThread().getName().contains("2")){
System.out.print("繁琐的任务。。。");
for(int i=0;i<100;i++){
}
Thread.sleep(300000);
System.out.println("任务是。。。"+Thread.currentThread().getName());
}
// Thread.sleep(200);
return (T) ("result of TaskWithResult " + id+"当前线程:"+Thread.currentThread().getName());
}
}