completable-future

Spring @Cacheable and @Async annotation

谁说胖子不能爱 提交于 2020-08-06 09:15:10
问题 I have the need to cache some the results of some asynchronous computations. In detail, to overcome this issue, I am trying to use Spring 4.3 cache and asynchronous computation features. As an example, let's take the following code: @Service class AsyncService { @Async @Cacheable("users") CompletableFuture<User> findById(String usedId) { // Some code that retrieves the user relative to id userId return CompletableFuture.completedFuture(user); } } Is it possible? I mean, will the caching

CompletableFuture, mutable objects and memory visibility

青春壹個敷衍的年華 提交于 2020-07-04 07:36:10
问题 I'm trying to understand how CompletableFuture in Java 8 interacts with the Java memory model. It seems to me that for programmer sanity, the following should ideally hold true: Actions in the thread that completes a CompletableFuture happen-before any completions dependent stages are executed Actions in the thread that registers a completion creates a dependent stage happen-before the completion dependent stage is executed There's a note in java.util.concurrent documentation saying that: