Skip to content

Tag: concurrency

How to combine 3 or more CompletionStages?

If have 2 CompletionStages, I can combine them with thenCombine method: If I have 3 or more CompletionStages, I can make a chain of thenCombine methods, but I have to use temporary objects to pass results. For example, here is a solution using Pair and Triple from the org.apache.commons.lang3.tuple package: I…

CompletableFuture from Callable?

Today I experimented with the “new” CompletableFuture from Java 8 and found myself confused when I didn’t find a runAsync(Callable) method. I can do it myself like shown below, but why is this (to me very obvious and useful utility method) missing? Am I missing something? Answer You are supp…

What state is a sleeping thread in?

I’m looking for verification/arguments on the following: A thread is in exactly one of the 5 (+1 — 2 for WAITING) states at any point of time. Suppose a thread T calls Thread.sleep(3000); and thus puts itself into sleep for 3 secs. Which state is it in during those 3 secs? It’s clearly start…