This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
Hi...I m confused about a Thread question in a mock
Which of the following are true: (Select one Correct answer)
a. The wait(), notify() and notifyAll() methods should be executed inside a synchronized code to avoid any compiler error. b. A call to notify() will throw an IllegalAccessException if there are no threads waiting. c. If a thread with a higher priority than the current running thread moves to the Ready-to-run state then the higher priority thread starts executing. d. Calling notify() method on an object implementing the Runnable interface will cause a thread that called the wait() method while owning the monitor of the object to be enabled for running. e. When yield() method is called on a thread, the current thread will sleep for some time while some other threads are doing some work. f. The thread that has been for the longest time in the Ready-to-run state gets the CPU when an another thread relinquishes the CPU.
I think the correct option is C.But in option D what does the term "enabled for running" mean...is it runnable state or running...if it is runnable then option D is right too....But all JVM s need not use the same method to choose the running thread as mentioned in option C...please help
A is wrong, because using wait, notify and notifyAll methods while not in synchronized code causes a runtime exception IllegalMonitorStateException, not a compiler error. B is wrong, because if no threads are waiting, calling notify will not produce any exceptions. C and F is wrong, because the actual behavior of the thread scheduler is undefined by the Java specification, it's platform-specific. On Windows, for example, the C statement is not true. D is true. "Enabled for running" means "in the ready-to-run state". E is false, because yield is a static method, and it affects the currently executing thread, moving it to the "ready-to-run" state, not in "sleep" state. [ December 19, 2007: Message edited by: Serge Petunin ]