Page 1 of 1

About Question enthuware.ocpjp.v21.2.4000 :

Posted: Tue Mar 04, 2025 6:56 pm
by shear12345
One of the correct answers suggests that the call to "Thread.sleep(10000)" can be replaced with "while(!isInterrupted()) {}". However, the context in which suggested replacement is within a class that implements the Runnable interface. The A class does NOT extend the Thread class. So there is no "isInterrupted" method to be called in this context. The aforementioned correct answer should have it's wording changed to suggest "while(!Thread.interrupted()) {}". This caused me to avoid this answer, because I knew that the Runnable functional interface does not define a default method called "isInterrupted"; and thus one of my answers was marked as incorrect.

Re: About Question enthuware.ocpjp.v21.2.4000 :

Posted: Wed Mar 05, 2025 12:10 am
by admin
You are right. Besides that there is another issue with the question. The main thread creates a virtual thread and since virtual threads are always daemon threads, the JVM will exit without waiting for the thread t to finish.
Both are now fixed and the explanation has been enhanced to explain both the points.

thank you for your feedback!