LearnFrenzy
Sign in Take a free test

Concurrency and Executors · Exercise 1 of 4

Concurrency and Executors Concurrency and Executors MCQ

  • 20 questions
  • Page 2 of 2
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

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.

Question 11 Medium

What does .exceptionally(ex -> fallback) do?

A Throws ex
B Returns the fallback value if the previous stage failed; otherwise passes the result through
C Retries the task
D Logs and ignores
Question page & discussion
Question 12 Medium

How does CompletableFuture.join() differ from get()?

A join does not wait
B join throws the unchecked CompletionException instead of the checked ExecutionException/InterruptedException
C join returns null on failure
D They are identical
Question page & discussion
Question 13 Medium

How does AtomicInteger.incrementAndGet() stay thread-safe without a lock?

A It uses synchronized internally
B It uses a hardware compare-and-set (CAS) instruction, retrying if another thread changed the value
C It runs on one thread
D It is not thread-safe
Question page & discussion
Question 14 Medium

Why is map.merge(word, 1, Integer::sum) safe on a ConcurrentHashMap while map.put(word, map.get(word) + 1) is not?

A merge is faster
B merge performs the read-modify-write atomically for that key; get-then-put can interleave with other threads and lose updates
C put is not allowed
D There is no difference
Question page & discussion
Question 15 Easy

Where should lock.unlock() be called?

A At the end of the method
B In a finally block after lock(), so the lock is released even if an exception occurs
C Before lock()
D It is not needed
Question page & discussion
Question 16 Medium

What does lock.tryLock(1, TimeUnit.SECONDS) allow?

A Locking twice
B Giving up if the lock is not available within a second – useful to avoid deadlock
C Unlocking automatically
D Reading without locking
Question page & discussion
Question 17 Hard

Which statement is correct?

A Both can be reset
B A CountDownLatch is one-shot (counts down to zero once); a CyclicBarrier makes a fixed group wait for each other and can be reused
C A barrier is one-shot
D They are the same
Question page & discussion
Question 18 Easy

What is a Semaphore with 3 permits used for?

A Running exactly 3 tasks
B Allowing at most 3 threads to use a resource at the same time
C Counting to 3
D Creating 3 threads
Question page & discussion
Question 19 Medium

What happens when a producer calls put on a full ArrayBlockingQueue?

A The item is dropped
B The producer blocks until space becomes available
C An exception is thrown
D The queue grows
Question page & discussion
Question 20 Medium

Which workload benefits most from Java 21 virtual threads?

A Heavy number crunching on 8 cores
B Thousands of concurrent tasks that mostly wait on I/O (HTTP, database)
C A single-threaded loop
D GUI rendering
Question page & discussion
Up next · Exercise 2Predict the Output20 questions

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links