File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "threads" Watch "threads" New topic


durga krishna

Joined: Jan 19, 2001
Posts: 17
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...
Fawad Khan
Ranch Hand

Joined: Feb 13, 2001
Posts: 36
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.

Seeking Certification
Mafalda Alabort

Joined: Mar 02, 2001
Posts: 24
when timeout expires the thread moves to the seeking lock state.
It explicitly says so in the Java 2 Certification Study Guide.
I hope it helps.
Vegad Arvind
Ranch Hand

Joined: Jan 10, 2001
Posts: 42
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.
I agree. Here's the link:
subject: threads
It's not a secret anymore!