This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help me out with Threads.

 
sreelakshmi sarma
Ranch Hand
Posts: 130
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18671
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
sreelakshmi sarma
Ranch Hand
Posts: 130
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Jim.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic