Answer Posted / shweta
Thread.sleep() sends the current thread into the "Not
Runnable" state for some amount of time. The thread keeps
the monitors it has aquired -- i.e. if the thread is
currently in a synchronized block or method no other thread
can enter this block or method. If another thread calls
t.interrupt() it will wake up the sleeping thread.
Note that sleep is a static method, which means that it
always affects the current thread (the one that is
executing the sleep method). A common mistake is to call
t.sleep() where t is a different thread; even then, it is
the current thread that will sleep, not the t thread.
t.suspend() is deprecated. Using it is possible to halt a
thread other than the current thread. A suspended thread
keeps all its monitors and since this state is not
interruptable it is deadlock prone.
object.wait() sends the current thread into the "Not
Runnable" state, like sleep(), but with a twist. Wait is
called on a object, not a thread; we call this object
the "lock object." Before lock.wait() is called, the
current thread must synchronize on the lock object; wait()
then releases this lock, and adds the thread to the "wait
list" associated with the lock. Later, another thread can
synchronize on the same lock object and call lock.notify().
This wakes up the original, waiting thread. Basically, wait
()/notify() is like sleep()/interrupt(), only the active
thread does not need a direct pointer to the sleeping
thread, but only to the shared lock object.
Is This Answer Correct ? | 11 Yes | 0 No |
Post New Answer View All Answers
Which class is the immediate superclass of the menucomponent class?
what is the use of State Factories?
Is the ternary operator written x : y ? Z or x ? Y : z ?
What are the different approaches to represent an inheritance hierarchy?
when A client sent a request to the server to open facebook page and close the browser after this request .at that time the same user do login by using a different browser then that session id will exist or not for the same client??
What is the purpose of the finally clause of a try-catch-finally statement?
What is ioc concept & explain it?
If your ui seems to freeze periodically, what might be a likely reason?
What is the difference between ear, jar and war file?
how to use debug in my elipse to solve problems that exist in my project
What is a class loader?
What modifiers may be used with an inner class that is a member of an outer class?
If we opened Windows Internet Explorer 4 times, does it starts 4 processes or 4 threads?
What are the different types of exception?
A user of a web application sees a jsessionid argument in the URL whenever a resource is accessed. What does this mean? a. The form must have the field jsessionid b. URL rewriting is used as the session method c. Cookies are used for managing sessions