completable-future

CompletableFuture how to return first FALSE or wait until all are completed to return TRUE

拈花ヽ惹草 提交于 2021-01-29 13:33:56
问题 I have a bit of an odd situation that doesn’t seem to allow this peg to fit into any of the widely established CompletableFuture holes. Within a primary method that is evaluating returned booleans, I am wanting to allow calls to three different methods to complete asynchronously. Each of these three methods can return either a TRUE or a FALSE. If any return a FALSE, I want the evaluation to drop the remainder and simply return that FALSE value. The point being, it can be any of the three, not

Is the writer's reason correct for using thenCompose and not thenComposeAsync

家住魔仙堡 提交于 2021-01-20 18:20:52
问题 This question is different from this one Difference between Java8 thenCompose and thenComposeAsync because I want to know what is the writer's reason for using thenCompose and not thenComposeAsync . I was reading Modern Java in action and I came across this part of code on page 405: public static List<String> findPrices(String product) { ExecutorService executor = Executors.newFixedThreadPool(10); List<Shop> shops = Arrays.asList(new Shop(), new Shop()); List<CompletableFuture<String>>

is using @Async and CompletableFuture in controller can increase performance of our api?

我的未来我决定 提交于 2021-01-18 04:24:36
问题 What I am trying to achieve is can I get a better performance by using @Async and CompletableFuture as result in my controller of my RESTApi by using the multi threading in this simple way? here is what I do, here is my controller : @PostMapping("/store") @Async public CompletableFuture<ResponseEntity<ResponseRequest<CategoryBpsjResponseDto>>> saveNewCategoryBPSJ(@Valid @RequestBody InputRequest<CategoryBPSJRequestDto> request) { CompletableFuture<ResponseEntity<ResponseRequest

is using @Async and CompletableFuture in controller can increase performance of our api?

大憨熊 提交于 2021-01-18 03:57:13
问题 What I am trying to achieve is can I get a better performance by using @Async and CompletableFuture as result in my controller of my RESTApi by using the multi threading in this simple way? here is what I do, here is my controller : @PostMapping("/store") @Async public CompletableFuture<ResponseEntity<ResponseRequest<CategoryBpsjResponseDto>>> saveNewCategoryBPSJ(@Valid @RequestBody InputRequest<CategoryBPSJRequestDto> request) { CompletableFuture<ResponseEntity<ResponseRequest

Letting CompletableFuture exceptionally() handle a supplyAsync() Exception

时间秒杀一切 提交于 2021-01-01 04:20:34
问题 The question is rather simple: I'm looking for an elegant way of using CompletableFuture#exceptionally alongside with CompletableFuture#supplyAsync . This is what does not work: private void doesNotCompile() { CompletableFuture<String> sad = CompletableFuture .supplyAsync(() -> throwSomething()) .exceptionally(Throwable::getMessage); } private String throwSomething() throws Exception { throw new Exception(); } I thought the idea behind exceptionally() was precisely to handle cases where an

Letting CompletableFuture exceptionally() handle a supplyAsync() Exception

瘦欲@ 提交于 2021-01-01 04:17:58
问题 The question is rather simple: I'm looking for an elegant way of using CompletableFuture#exceptionally alongside with CompletableFuture#supplyAsync . This is what does not work: private void doesNotCompile() { CompletableFuture<String> sad = CompletableFuture .supplyAsync(() -> throwSomething()) .exceptionally(Throwable::getMessage); } private String throwSomething() throws Exception { throw new Exception(); } I thought the idea behind exceptionally() was precisely to handle cases where an

How to execute an Array of CompletableFuture and compose their results

泪湿孤枕 提交于 2020-12-31 04:48:20
问题 I am investigating Java 8 CompletableFutures and read (and seen) that I should employ thenCompose instead of thenApply . I have converted my code to use thenCompose but I have a feeling in an incorrect manner. Here is my controlling code... final CompletableFuture<List<String>> extractor = get(htmlPageSource); @SuppressWarnings("unchecked") final CompletableFuture<List<Documentable>>[] completableFutures = new CompletableFuture[ENDPOINT.EXTRACTABLES.size()]; int index = 0; for( ENDPOINT

How to execute an Array of CompletableFuture and compose their results

那年仲夏 提交于 2020-12-31 04:41:58
问题 I am investigating Java 8 CompletableFutures and read (and seen) that I should employ thenCompose instead of thenApply . I have converted my code to use thenCompose but I have a feeling in an incorrect manner. Here is my controlling code... final CompletableFuture<List<String>> extractor = get(htmlPageSource); @SuppressWarnings("unchecked") final CompletableFuture<List<Documentable>>[] completableFutures = new CompletableFuture[ENDPOINT.EXTRACTABLES.size()]; int index = 0; for( ENDPOINT

How to execute an Array of CompletableFuture and compose their results

一笑奈何 提交于 2020-12-31 04:40:39
问题 I am investigating Java 8 CompletableFutures and read (and seen) that I should employ thenCompose instead of thenApply . I have converted my code to use thenCompose but I have a feeling in an incorrect manner. Here is my controlling code... final CompletableFuture<List<String>> extractor = get(htmlPageSource); @SuppressWarnings("unchecked") final CompletableFuture<List<Documentable>>[] completableFutures = new CompletableFuture[ENDPOINT.EXTRACTABLES.size()]; int index = 0; for( ENDPOINT

How to execute an Array of CompletableFuture and compose their results

狂风中的少年 提交于 2020-12-31 04:40:00
问题 I am investigating Java 8 CompletableFutures and read (and seen) that I should employ thenCompose instead of thenApply . I have converted my code to use thenCompose but I have a feeling in an incorrect manner. Here is my controlling code... final CompletableFuture<List<String>> extractor = get(htmlPageSource); @SuppressWarnings("unchecked") final CompletableFuture<List<Documentable>>[] completableFutures = new CompletableFuture[ENDPOINT.EXTRACTABLES.size()]; int index = 0; for( ENDPOINT