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
What do you need to set-up a cluster with jboss?
Which class is the immediate superclass of the menucomponent class?
How to implement dphibernate to activate lazy loading in Flex with java ?thanx in advance!
What are various types of class loaders used by jvm?
Java is fully object oriented languages or not?
What is re-entrant. Is session beans reentrant. Is entity beans reentrant?
What are the different methods of identifying an object?
What is a modular application?
Describe activation process?
What you mean by COM and DCOM?
Is “abc” a primitive value?
What is a class loader? What are the different class loaders used by jvm?
Define prototype?
Why use POJO when I can use hashmap
how do you Handle Front End Application data against DB with example?