Loading topic
start, join, sleep, and interrupt.2 min readjoin. Each thread did its own work. Now we will look at what happens when two threads touch the same data at the same time. This is where many bugs in concurrent programs come from.2 min readsynchronized, volatile, and atomic variables.2 min readnew Thread(...). That works for one or two jobs. Real programs often have hundreds of small jobs, and creating a new thread for each one is slow and wasteful. Java has a better tool for this.3 min readExecutorService. Those tasks were Runnables, so they did their work and returned nothing. Often you want an answer back, such as a computed number or a downloaded page. Java gives you two tools for this: Callable and Future.3 min readFuture.get() to read a task's result. Tasks don't always succeed, though. A task might divide by zero, read a missing file, or try to parse bad input. This chapter shows where that error ends up and how to catch it.2 min readExecutorService one at a time with submit. Sometimes you have a whole batch of tasks instead. You might want every result, or you might want only the first good one. Java gives you two methods for these cases: invokeAll and invokeAny.2 min readExecutors factory methods are quick to use, but they make choices for you. Sometimes you need to set those choices yourself. ThreadPoolExecutor is the class behind most of those factory methods, and you can build one directly to control how many threads it uses and what happens when it gets 2 min readFuture to get a result back from a task. A Future has one weakness. To use its value, you must call get(), and get() makes your thread wait. A CompletableFuture removes that wait. It lets you say "when this result is ready, do this next step," and it keeps goin2 min read