Contact

Found an error in a question, need help restoring a purchase, or have a privacy request? Email social@sitesouk.com.

When reporting a question, include the page address (it ends in the question's name) and what you think is wrong. Each question links to the source it comes from (the regulation or FAA guide, angular.dev, or the Java SE documentation), so a pointer to the conflicting text helps us fix it fast.

Send feedback

Use this form for a wrong or unclear question, a bug, or an idea. No account needed.

Reporting this Java 25 question: Consider the following Java code snippet utilizing virtual threads in Java 25. The `Worker` class uses a `ReentrantLock` to protect a shared counter, while an alternative approach might use the `synchronized` keyword on the `increment` method. ```java import java.util.concurrent.locks.ReentrantLock; class SharedResource { private int counter = 0; private final ReentrantLock lock = new ReentrantLock(); public void increment() { lock.lock(); try { // Simulate some work that might be blocking/I/O bound Thread.sleep(10); counter++; } catch (InterruptedException e) { Thread.currentThread().interrupt(); } finally { lock.unlock(); } } public int getCounter() { return counter; } } public class VirtualThreadTest { public static void main(String[] args) throws Exception { SharedResource resource = new SharedResource(); // Create and run multiple virtual threads concurrently Runnable task = () -> { for (int i = 0; i < 100; i++) { resource.increment(); } }; Thread.ofVirtual().start(task); Thread.ofVirtual().start(task); Thread.ofVirtual().start(task); // Wait for threads to finish (simplified wait for demonstration) Thread.sleep(500); System.out.println("Final Counter: " + resource.getCounter()); } } ``` Assuming the `Thread.sleep(10)` inside the critical section simulates an I/O-bound operation that benefits significantly from virtual threads' non-blocking nature, what is the *primary* performance difference expected between using `ReentrantLock` (as shown) and replacing the lock mechanism with a simple `synchronized` block on the `increment` method when running with many virtual threads?

What kind of feedback?
How is the site working for you? Optional.

We attach the question you are reporting (if any) and your browser type. We do not attach your IP address.

exams.setupmycode.com is operated by Sitesouk LLC. It is not affiliated with the FAA, PSI, Google, the Angular team, or Oracle. We cannot answer questions about scheduling or taking the official FAA test; for that, contact PSI or the FAA directly.