我有以下代码
private List<String[]> userList2 = new ArrayList<String[]>(10000);
ThreadPoolExecutor executor = new ThreadPoolExecutor(10, 10, 10, TimeUnit.SECONDS,
new ArrayBlockingQueue<Runnable>(5), new ThreadPoolExecutor.CallerRunsPolicy());
数据库查询
while (rs.next())
{
data = new String[2];
data[0] = rs.getString("userid");
data[1] = rs.getString("email");
userList2.add(data);
if(userList2.size()==10000) //Confusion in this part..
{
final List<String[]> elist = new ArrayList<String[]>(userList2);
executor.execute(new Runnable() {
public void run() {
doBilling(con,elist); //Parallel is not happening here...
}
});
我有一个方法
doBillng(Connection con,List<String[]> userList)
{
String list[]=null;
String userid=" ";
for(int i=0;i<userList.size();i++)
{
list=userList.get(i);
userid=props[0];
list = BillingDao.billById(uid, con);
}
}
当 userlist2 大小为 10000 时,我想在 10 个线程中并行运行 doBilling,以便它可以以极快的速度达到 10000 条记录。但它没有发生!请建议我做错了什么以及应该如何解决..
提前致谢