java线程池开启多线程

  // //maximumPoolSize设置为2 ,拒绝策略为AbortPolic策略,直接抛出异常
ThreadPoolExecutor pool = new ThreadPoolExecutor(5, 10, 1000000, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(20000), Executors.defaultThreadFactory(),new ThreadPoolExecutor.AbortPolicy());
for(int i=0;i<3;i++) { //10000
Callable threadUserTask = new ThreadBankCardTestTask(i);
Future<String> res = pool.submit(threadUserTask);//异步提交, non blocking.
/* synchronized(TaskLock.lockA){
if(StringUtils.isEmpty(res.get()))
System.out.println("开始执行sql脚本,i"+i);
jdbcTemplate.execute(res.get());
System.out.println("结束了执行sql脚本,i"+i);
}
*/
System.out.println("外部执行核心线程,i="+i);
}
posted @ 2021-12-07 10:24  ☆♂安♀★  阅读(498)  评论(0编辑  收藏  举报