使用线程开启任务

//使用多线程技术,提高程序的效率    
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
5,
20,
5000,
TimeUnit.MILLISECONDS,
new ArrayBlockingQueue<>(5),
new NamedThreadFactory("thread-pool", false),
new ThreadPoolExecutor.AbortPolicy());
threadPoolExecutor.submit(new Runnable() {//
@SneakyThrows
@Override
public void run() {
initDate(dbRsglKhsjsz);
threadPoolExecutor.shutdown();
}
});


需要引入jar包
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.1.3</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.22</version>
<scope>provided</scope>
</dependency>
posted on 2022-08-05 17:57  IT-QI  阅读(42)  评论(0编辑  收藏  举报