Skills101
← All practice quizzes

Quiz: Java Concurrency Utilities

5 questions · new set on every retakeNo time limitPass: 60%+10 XP on first pass

The java.util.concurrent tools that replace most hand-written synchronized code: atomic variables and compare-and-set, ConcurrentHashMap.merge, invokeAll, CountDownLatch, and CompletableFuture pipelines.

Log in to take the quiz

Free account · see your score, answers and explanations, earn XP

  1. Question 1

    Why can two threads running count++ on a shared int lose updates?

  2. Question 2

    What does this print?

    import java.util.concurrent.atomic.*;
    public class Main {
        public static void main(String[] args) {
            AtomicInteger a = new AtomicInteger(10);
            boolean ok = a.compareAndSet(5, 7);
            System.out.println(ok + " " + a.incrementAndGet());
        }
    }
    
  3. Question 3

    What does compare-and-set (CAS) do?

  4. Question 4

    Which call counts a word in a ConcurrentHashMap safely from many threads?

  5. Question 5

    What does this print?

    import java.util.concurrent.*;
    public class Main {
        public static void main(String[] args) {
            String r = CompletableFuture.supplyAsync(() -> 6)
                .thenApply(x -> x * 7)
                .thenApply(x -> "answer=" + x)
                .join();
            System.out.println(r);
        }
    }
    
🎯 Today’s placement challenge — 10 questions, no login. Can you score 10/10?Take today’s challenge →