Test 26 - Free Java SE 25 certification Mock test - Exam Code 1Z0-831-Oracle certified Java SE 25 Professional
Concurrency has changed enormously with virtual threads and the Java SE 25 Developer exam is very much reflective of that. The free 1Z0-831 mock test available covers creating both platform and virtual threads, Runnable and Callable tasks, the thread lifecycle, executor services and scoped values. That's the first of the multithreading objectives.
You start off with thread creation. The questions look at the difference between extending Thread and passing a Runnable and explain why calling run will execute the code on the current thread whereas calling start will spawn a new thread. Calling start twice will of course throw an IllegalThreadStateException and that's a detail that crops up again and again. You'll also be using the Thread.ofPlatform and Thread.ofVirtual builders and Thread.startVirtualThread. You'll learn that virtual threads are lightweight, are scheduled by the JVM onto a carrier thread and are always daemon threads. There's a set of questions around when a virtual thread is a good choice (it's for blocking and I/O heavy work) and when it isn't (it's not for long CPU bound computation).
Life cycle questions. You'll be tracking the various states (NEW, RUNNABLE, BLOCKED, WAITING, TIMED_WAITING, TERMINATED) and predicting what join, sleep, interrupt and isAlive do in a given sequence. Interrupt handling is tested via InterruptedException and the interrupted status flag.
Executors get extensive coverage. You'll be using Executors.newFixedThreadPool, Executors.newCachedThreadPool, Executors.newSingleThreadExecutor, Executors.newVirtualThreadPerTaskExecutor and the various scheduled executors. You'll be comparing submit with execute. Callable returns a value via a Future so you'll be looking at get (including the checked exceptions), cancel and isDone. You'll also be looking at why an ExecutorService must be shut down and the difference between shutdown and shutdownNow. Given that ExecutorService is AutoCloseable you'll be looking at try-with-resources as well.
Scoped values are new for this exam. ScopedValue allows a method to share immutable data with the code it calls and with any child tasks it spawns for a limited period of time. You'll be asked to predict what a bound value will return both inside and outside of its scope and you'll be expected to contrast this with ThreadLocal (which is mutable and persists for the lifetime of the thread). Be on the lookout for questions on pinning too. Native calls can cause a virtual thread to be pinned to its carrier thread, which in turn limits scalability. You'll also be asked why you wouldn't want to pool virtual threads (they're cheap and were designed to be used for exactly one task).
Every explanation will state the rule that governs the answer. Take the test, go through each one you get wrong and run a few little examples with both thread types to see the difference for yourself.
