s=conn.createStatement();
String sql="SELECT COUNT(*) count from t_wlk where (status=19 or status=0) and department in ('dx','dxft');";
ResultSet rs=s.executeQuery(sql);
rs.next();
count=Integer.parseInt(rs.getString("count"));
System.out.println(sdf.format(time)+" 开始更新卡状态……");
System.out.println("本次应处理条数:"+count);
if(count<200){
thread_num = 1;
action=count+1;
}else if(count<1000){
thread_num = 3;
action=(count/3)+1;
}else if(count<3000){
thread_num = 5;
action=(count/5)+1;
}else if(count<10000){
thread_num = 10;
action=(count/10)+1;
}else {
thread_num = 20;
action=(count/20)+1;
}
executor = Executors.newFixedThreadPool(thread_num);
for(int i=0;i<thread_num;i++){
final int begin_num = i*action;
Runnable runn = new Runnable() {
@Override
public void run() {
action(begin_num);
}
};
System.out.print("t"+i+"启动 ,");
executor.execute(runn);
}
System.out.println();
} catch (Exception e) {
e.printStackTrace();
}finally{
CardDao.close(conn);
CardDao.closeStment(s);
executor.shutdown();
while(true){
if(executor.isTerminated()){
time=new Date();
System.out.println("本次已经处理完了的条数:"+number);
System.out.println("其中月套餐的条数是:"+costsnum);
System.out.println("其中累计卡的条数是:"+addnum);
System.out.println(sdf.format(time));
break;
}
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}