aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Thread question from mock Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Thread question from mock" Watch "Thread question from mock" New topic
Author

Thread question from mock

Sugantha Jeevankumar
Ranch Hand

Joined: Jun 06, 2007
Posts: 93
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


SCJP 5.0
Panseer Kaur
Ranch Hand

Joined: Nov 01, 2007
Posts: 44
Yeah option C is not correct. You never know what thread will be executed. You can set the priority but what runs is up to the JVM.

As far as D goes I believe they mean that it's in the runnable state. I believe D Is the correct answer but it's worded pretty strangely so I'm not 100%.
Sergey Petunin
Ranch Hand

Joined: Dec 16, 2007
Posts: 44
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 ]
Sugantha Jeevankumar
Ranch Hand

Joined: Jun 06, 2007
Posts: 93
Thanks people...its clear now...
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Thread question from mock