What does .exceptionally(ex -> fallback) do?
handle receives both the result and the exception.
Concurrency and Executors · Exercise 1 of 4
Twenty multiple-choice questions on java.util.concurrent: executors, Callable and Future, CompletableFuture, locks, atomics, concurrent collections, synchronizers and virtual threads. Pick an option to check your answer instantly.
What does .exceptionally(ex -> fallback) do?
handle receives both the result and the exception.
How does CompletableFuture.join() differ from get()?
That makes join convenient inside lambdas and streams.
How does AtomicInteger.incrementAndGet() stay thread-safe without a lock?
LongAdder spreads updates over cells for even less contention.
Why is map.merge(word, 1, Integer::sum) safe on a ConcurrentHashMap while map.put(word, map.get(word) + 1) is not?
compute and putIfAbsent are also atomic.
Where should lock.unlock() be called?
Unlike synchronized, explicit locks are not released automatically.
What does lock.tryLock(1, TimeUnit.SECONDS) allow?
It returns true if the lock was acquired.
Which statement is correct?
Latch: "wait for N events"; barrier: "wait for each other".
What is a Semaphore with 3 permits used for?
acquire() takes a permit, release() returns it.
What happens when a producer calls put on a full ArrayBlockingQueue?
take blocks when the queue is empty; offer/poll have non-blocking and timed variants.
Which workload benefits most from Java 21 virtual threads?
Blocking a virtual thread is cheap, so thread-per-request scales.
Timed online tests with instant scores and explanations.