About Question enthuware.ocpjp.v21.2.4000 :
Moderators: Site Manager, fjwalraven
-
- Posts: 18
- Joined: Wed Feb 12, 2025 4:56 pm
About Question enthuware.ocpjp.v21.2.4000 :
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.
-
- Site Admin
- Posts: 10384
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v21.2.4000 :
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!
Both are now fixed and the explanation has been enhanced to explain both the points.
thank you for your feedback!
Who is online
Users browsing this forum: No registered users and 6 guests