• 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

Which of the following are true?

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which of the following are true?
A The sleep() method puts a thread in the ready state.
B The sleep() method puts a thread in the waiting state.
C The suspend()method is the preferred method for stopping a thread��s execution.
D A thread��s interrupt() method results in the throwing of the InterruptedException.
the Given ans:d
my ans:ad.
if the a is right?somebody give some comment .
 
Ranch Hand
Posts: 464
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Gong James:
Which of the following are true?
A The sleep() method puts a thread in the ready state.
B The sleep() method puts a thread in the waiting state.
C The suspend()method is the preferred method for stopping a thread��s execution.
D A thread��s interrupt() method results in the throwing of the InterruptedException.
the Given ans:d
my ans:ad.

if the a is right?somebody give some comment .


From JDK
public static void sleep(long millis)
throws InterruptedException
Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds. The thread does not lose ownership of any monitors.
Once the thread is awake, it cannot just jump into the running state. It goes to ready state and then contents with other threads for the CPU and at some point of time in the future it gets to run...
So sleep() does temporarily caeses the execution of the thread
but it does not put a thread to the ready state.
But once its awake it goes to the ready to run queue
Any body?
Ragu

[This message has been edited by Ragu Sivaraman (edited October 25, 2001).]
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A The sleep() method puts a thread in the ready state.
The sleep() method does not put the thread in the ready state. It just puts the thread in question in a "sleeping state". On waking from its sleep, the thread transits to the ready state.
B The sleep() method puts a thread in the waiting state.
According to me, this is the closest to the correct answer. According to Khalid Mughal, the sleep() method puts the thread in a sleeping state
C The suspend()method is the preferred method for stopping a thread��s execution.
suspend() method has been deprecated. So, this choice bombs.
D A thread��s interrupt() method results in the throwing of the InterruptedException.

A thread's interrupt() method does not throw InterruptedException. According to the API, it throws a SecurityException. The sleep() method, however, throws an InterruptedException.

Any Comments?
Shyam
[This message has been edited by Shyamsundar Gururaj (edited October 25, 2001).]
 
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


A thread's interrupt() method does not throw InterruptedException. According to
the API, it throws a SecurityException. The sleep() method, however, throws an
InterruptedException.


Invoking a thread's interrupt() method does throw an InterruptedException to that thread.
So, if that thread has previously invoked wait(), it will
receive this exception and awaken by it.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually Nain, you are right...In the "Method Details" of the interrupt() method, the API does not say that it throws an InterruptedException.
But the definition of the InterruptedException says ...


public class InterruptedException
extends Exception
Thrown when a thread is waiting, sleeping, or otherwise paused for a long time and another thread interrupts it using the interrupt method in class Thread.
Since:
JDK1.0
See Also:
Object.wait(), Object.wait(long), Object.wait(long, int), Thread.sleep(long), Thread.interrupt(), Thread.interrupted(), Serialized Form


So, the correct answer to the first post is, indeed, option (d)
Thanks
Shyam
[This message has been edited by Shyamsundar Gururaj (edited October 26, 2001).]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic