aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Help me out with 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 "Help me out with Threads." Watch "Help me out with Threads." New topic
Author

Help me out with Threads.

sreelakshmi sarma
Ranch Hand

Joined: Mar 02, 2000
Posts: 130
Please take a look at the following conditions that might stop a thread from executing and let me know if am wrong.
1. Thread is not the highest priority thread and so cannot get cpu time. //But it is in the runnable or ready state right???
2. The thread has been put to sleep using sleep method // it is not in the runnable state but it's alive???
3.There is more than one thread with the same highest priority and the system supports time slicing so, JVM is switching between these threads. // thread is in the runnable(ready) state right???
4. Some one has suspended the thread using the suspend() // not runnable???
The sleep method is depriceated. If i get a same question in the test suspend() won't be one of the choice right??? but if it's there should i pick it up or not.

5. The thread is waiting on a condition because someone invoked wait(). // not runnable???
6.The thread has explicitly yielded control by invoking yield() // runnable state???
7. It is blocked for file I/O // not runnable???
I am little confused with Runnable ,Ready ,Blocked, Stopped Executing and Not Runnable.
Could someone explain me the difference.
One more small question if i get a question like select all the thread methods that will stop the thread from executing and wait() is one among them. Should i pick it up or not. Since it's Object class's method.
Sorry for this very lengthy message.
Thanks a lot.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
It looks to me like the answer to all seven of your numbered questions is: yes. So you're not as confused as you think you are.
Regarding deprecated methods like stop(), suspend(), and resume(): I think Sun is less likely to ask you about these, but they could. If they are mentioned in a question, they could indeed be answers. You'll need to read the question carefully to determine the answer. They might say something like "excluding deprecated methods", in which case, don't chose a deprecated method as the answer. But if the question is just "what methods can stop a thread from executing" then stop() and suspend() are certainly valid answers.
"Runnable" includes "Ready" and "Running". "Not Runnable" would include everything else - "New", "Dead", and a bunch of different waiting-like states: "Waiting", "Blocked", "Sleeping", "Suspended", and "Seeking Lock". "Stopped Executing" is a little different - it implies that the state was once "Running" but now it isn't.
Your last question is toughest, as it's ambiguous. I would probably include wait() as an answer unless the question clearly asked about methods "of the Thread class" or better yet "defined in the Thread class" - then wait() should be excluded. Most real test questions will be more clearly phrased, so I wouldn't worry too much about this one.


"I'm not back." - Bill Harding, Twister
sreelakshmi sarma
Ranch Hand

Joined: Mar 02, 2000
Posts: 130
Thanks a lot Jim.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help me out with Threads.