demo
Demo
public class Test {
/**
* 错误查询违章job ,失败重查
*/
static class ViolationMemberCaller implements Runnable {
private String name;
public ViolationMemberCaller(String name) {
super();
this.name = name;
}
@Override
public void run() {
try {
Thread.sleep(6000);
System.out.println("name=" + name + ";" + Thread.currentThread().getName());
} catch (Exception e) {
}
}
}
public static void main(String[] args) throws Exception {
final long start = System.currentTimeMillis();
// 创建线程池 (线程IO 6秒,(四核测试数据:delay 10毫秒(1w 60s 10W 600秒);delay 6秒(1w 66s 10W 606秒)))
ScheduledExecutorService scheduledThreadPool = Executors.newScheduledThreadPool(1000);
// TODO CESHI
for (int i = 0; i < 100000; i++) {
scheduledThreadPool.schedule(new ViolationMemberCaller(i + ""), 6, TimeUnit.SECONDS);
// scheduledThreadPool.scheduleAtFixedRate(new ViolationMemberCaller(0 + ""), 1,
// 10, TimeUnit.MILLISECONDS);
}
// 关闭线程池
scheduledThreadPool.shutdown();
try {
scheduledThreadPool.awaitTermination(5, TimeUnit.HOURS);
} catch (Exception e) {
}
final long end = System.currentTimeMillis();
System.out.println("所有的子线程都结束了,共耗时:" + (end - start) / 1000 + "秒");
}
}
Last updated
Was this helpful?