• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Thread question from mock

 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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%.
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks people...its clear now...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic