ava异步执行可以使用线程,或者第三方消息中间件,如mq
线程池的使用:
private BlockingQueue<Runnable> taskQueue = new ArrayBlockingQueue<>(100);
private RejectedExecutionHandler rejectedExecutionHandler = (r, executor) -> log.error("BlockingQueue is full in AppointFacadeImpl");
private ManagedThreadPool executor = new ManagedThreadPool(8, 16, 60L, TimeUnit.SECONDS, taskQueue, new NamedThreadFactory("CheetahClientImplThreadPool"), rejectedExecutionHandler);
executor.execute(() -> {
//task
List<ShopServiceInfo> shopServiceInfos = shopServiceInfoService.selectByServiceSns(shopId, appointCarTokenVo.getItemIds().toArray(new String[]{}));
createAppointByCarToken(shopServiceInfos, appintSn, shopId, appointCarTokenVo, redisKey);
});