多线程
// 避免公司数量过多,要分批次执行
for (int i = 0; i < a; i++) {
// 获取业知识平台每日推送数据表中的数据用于查询企查查获取数据
List<Map<String, String>> complist = CompSelfRiskScan.getQCCCheckCompList(maxNum, datadate, CLASS_NAME);
if (complist != null && complist.size() > 0) {// 从企业知识平台抽取的数据表有数据
int l = complist.size() / 3;
if (l > 0) {// 从数据库中得到的数据至少有3条
// timeExcuted();//原先的不用了
if(i==0){
timerTaskUtils = new TimerTaskUtils();
new Timer(true).schedule(timerTaskUtils, TimerTaskUtils.executionDate(Calendar.HOUR, 10));
ARE.getLog().info(CLASS_NAME + "类,定时器设置完毕");
}
Thread td1 = new Thread() {
@Override
public void run() {
for (int t = 0 * l; t < 1 * l; t++) {
if (timerTaskUtils.isAction()) {
ARE.getLog().info(CLASS_NAME +"类,定时器工作结束了");
break;
}
excuteMethod(complist, t, sTmStamp, key, url, SecretKey, rtdescribe);
}
}
};
td1.start();
ARE.getLog().info(CLASS_NAME + "类,在i的值为:" + i + "时,td1启动");
Thread td2 = new Thread() {
@Override
public void run() {
for (int t = 1 * l; t < 2 * l; t++) {
if (timerTaskUtils.isAction()) {
ARE.getLog().info(CLASS_NAME +"类,定时器工作结束了");
break;
}
excuteMethod(complist, t, sTmStamp, key, url, SecretKey, rtdescribe);
}
}
};
td2.start();
ARE.getLog().info(CLASS_NAME + "类,在i的值为:" + i + "时,td2启动");
Thread td3 = new Thread() {
@Override
public void run() {
for (int t = 2 * l; t < complist.size(); t++) {
if (timerTaskUtils.isAction()) {
ARE.getLog().info(CLASS_NAME +"类,定时器工作结束了");
break;
}
excuteMethod(complist, t, sTmStamp, key, url, SecretKey, rtdescribe);
}
}
};
td3.start();
try {
td1.join();
td2.join();
td3.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ARE.getLog().info(CLASS_NAME + "类,在i的值为:" + i + "时,td3启动");
} else {// 数据小于3条
for (int t = 0; t < complist.size(); t++) {
excuteMethod(complist, t, sTmStamp, key, url, SecretKey, rtdescribe);
}
}
}
}
******************************注意join多个的使用,放在一起,不要忘记start();
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构