我只想到了两种办法:1. 共享变量2. 采用任务链表
Java 里有没有现成的办法判定线程池里的工作任务做完吗?
Java 里有没有现成的办法判定线程池里的工作任务做完吗?
解决方案 »
- jsp中如何取spring3的注解@value中的值
- Glassfish里应用出现WebappClassLoader unable to load resource问题
- httpclient post是否适合高并发传输数据 ?谢谢!
- 如何使用hibernate将大于4k的文件插入数据库表中的blob字段中
- 请教jfreechart时间序列图问题
- Hibernate报错Could not parse mapping document from resource
- Spring2.0通知里的一个表达式语法
- 一个关于action调用dao的问题
- <logic:iterate ><bean:write >应用时遇到困难 !!!在线等!!!!!!!!!!!!
- eclipse中有没有象jcretor那样 显示代码行的?
- MySql数据库设置问题
- 请问现在都用什么工具产生Hibernate数据库表映射文件
或者使用for循环的future.get也可以。
Future.get返回值更加用不上。
继续求解强解!
附贴部分代码:
package com.ifyours.statistics;import com.ifyours.statistics.fileoperator.FileProcess;
import com.ifyours.statistics.util.DateTime;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;import java.util.Date;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.logging.Level;
import java.util.logging.Logger;public class ServiceExecutor { public ServiceExecutor() throws IOException {
} public static void main(String[] args) {
File filepath = new File("t:/ifyours/advert01/");
Date date = DateTime.getDate("2011-08-14 08:30:00");
// 查找出文件夹下待分析的文件列表
HashMap<String, File> advertLogsFile = FileProcess.getAdvertFileList(filepath, date);
ArrayList<Future<Integer>> al = new ArrayList<Future<Integer>>();
boolean flag = true; ExecutorService es = Executors.newFixedThreadPool(3); for (Entry<String, File> entry : advertLogsFile.entrySet()) {
if (entry.getKey().indexOf("ip") != -1) {
// 执行线性,依次统计
al.add((Future<Integer>) es.submit(new AnalyseAdvertLogs(entry.getValue(), date, date)));
}
} while (flag) {
for (Future<Integer> fi : al) {
// 在这里我是想检测所有的返回对象是否已经做完,做完就可以执行一些写操作,完成后并把flag标志置false
if (fi.isDone()) {
try {
System.out.println(fi.get());
} catch (InterruptedException ex) {
Logger.getLogger(ServiceExecutor.class.getName()).log(Level.SEVERE, null, ex);
} catch (ExecutionException ex) {
Logger.getLogger(ServiceExecutor.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
}
}