【发布时间】:2020-08-07 20:47:28
【问题描述】:
我英语不好。
我使用异步方法。
选项 1
public CompletableFuture<Integer> getDiscountPriceAsync(Integer price) {
return CompletableFuture.supplyAsync(() -> {
log.info("supplyAsync");
return (int)(price * 0.9);
}, threadPoolTaskExecutor);
}
选项 2
@Async
public CompletableFuture<Integer> getDiscountPriceAsync(Integer price) {
return CompletableFuture.supplyAsync(() -> {
log.info("supplyAsync");
return (int)(price * 0.9);
}, threadPoolTaskExecutor);
}
我想知道使用@Async 和不使用它有什么区别。
我认为第一个 Option1 提供了足够的异步方法。
但是,像Option2那样使用是否正确?
【问题讨论】:
标签: java spring-boot asynchronous completable-future