JAVA提交异步任务的三种方式

方法一:CompletableFuture

CompletableFuture<List<UserDO>> userListFuture = CompletableFuture.supplyAsync(()->
                userMapper.selectByIds(ids));

方法二:注解Async

@Async

https://www.cnblogs.com/jpfss/p/10273129.html

方法三:线程池

创建全局线程池,把要执行的任务放到线程池中执行。


this.defaultExecutor = new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors() + 1,
Runtime.getRuntime().availableProcessors() + 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(1000));
posted @ 2021-01-19 15:29  六七十三  阅读(625)  评论(0编辑  收藏  举报