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);
}
上一篇:【JAVA】ThreadPoolExecutor参数


下一篇:java多线程---线程池了解