Loading topic
java.util.concurrent.Future to represent the result of work running on another thread. It solved one problem, getting a value back from a background task. It left several others open, and those gaps are the reason CompletableFuture exists. This chapter walks through each gap wi6 min readCompletableFuture instance: starting background work, wrapping a value you already have, and creating an empty future that you complete yourself. It assumes you know Java 8 lambdas and method references, ExecutorService basics, the functional interfaces `Sup5 min readCompletableFuture lets you describe work without waiting for it. At some point, though, a thread usually needs the value, for example main before it prints, or a test before it asserts. This chapter covers the methods that block for a result, how they differ, and when to avoid them.5 min readFunction, Consumer, and Runnable, and how to create a CompletableFuture with supplyAsync. It covers how to attach work to a future's result without blocking a thread.5 min readFunction and Supplier, ExecutorService, and the basics of supplyAsync and thenApply. It covers one operator, thenCompose. It explains why dependent asynchronous calls need it, how it behaves when something fails, and which mistakes come up mo6 min readFunction and Supplier, and the basics of supplyAsync and thenApply. You should also know that join waits for a result. Here you learn to merge the results of two futures that do not depend on each other.5 min readsupplyAsync, thenApply, join, and how a failed stage reports its exception wrapped in a CompletionException. Earlier chapters covered all of these.5 min readFunction, Consumer and Supplier, and the difference between checked and unchecked exceptions. You should also have seen supplyAsync, thenApply and join from earlier chapters.5 min readCompletableFuture chain. This chapter explains the default, when to replace it, and how to size and manage the replacement.5 min readsupplyAsync, thenApply, thenCompose, executors, and the common pool. It explains one question: on which thread does each stage of a pipeline run, and how do the Async method names change that?5 min readExecutorService, the functional interfaces Supplier and Consumer, and how checked and unchecked exceptions differ. It also assumes you have seen thenApply, thenAccept, join, and the exception wrapping covered in earlier chap6 min readsupplyAsync, thenApply and exceptionally. It also assumes you know how join and get wrap exceptions. A future that never completes is one of the most common failures in asynchronous code. A remote call hangs, a lock is never released,6 min readsupplyAsync, thenApply, thenCompose, allOf, handle, and orTimeout from earlier chapters, and that you understand ExecutorService. Most CompletableFuture bugs do not come from misusing one method. They come from threads, exceptions, and cancellation behav6 min read