Hi all i have adoubt in the wait( long millisec ) method.The API says This method causes the current thread (call it T) to place itself in the wait set for this object and then to relinquish any and all synchronization claims on this object. Thread T becomes disabled for thread scheduling purposes and lies dormant until one of four things happens... The specified amount of real time has elapsed, more or less
what happens after the specified time elapses...does it still remian int he waiting state or moves to the ready to run state waiting to get a lock on the object's montitor.... please explain in detail. thanx in advance... durga.
Hi durga, Threads have majorly 5 states. Running, ready, Suspended ( truncated in jdk1.2), blocked ( say on I/O ). So, when we make a sleep() call to a thread, it goes from RUNNING state to SLEEPING state ( for the specified period of time ) and remember when the time elapses, it does not continue execution right away. And the thread goes to the READY state. And then waits for the scheduler to allow the thread to execute. So, we can say the given time in SLEEP() method is the at least time for which the thread will stay inactive. Also remember that only way a thread can goto READY state from running and RUNNING state from READY is the call by YIELD() method. No other call makes a thread goto running state from SLEEP(), BLOCKED(). Hope that will help u.
Hi, After waiting is over the waited thread goes to ReadyState. But there is no gurantee that this will be next one to run. it is upto the thread scheduling mechanism to decide which is the next to run. Avi.