This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Which methods may cause a thread to stop executing? A. sleep(); B. stop(); C. yield(); D. wait(); E. notify(); F. notifyAll() G. synchronized()
Answers given are A, B, C, D. I understand that we don't have to worry about deprecated methods so B. won't be an answer that we would need to select. My questions are: On the exam, what is meant when they say a thread stops executing? 1. The thread is in Ready state just waiting for CPU time. 2. The thread is asleep (it is in a wait(), join(), sleep() or waiting for a lock). 3. The thread has terminated. 4. All of the above. Does 1. really count as the thread being stopped? Is waiting the same as stopped? [ February 01, 2004: Message edited by: Don Wood ]
Hi Don, I would guess the exam must be consistent with The Java Programming Language by Arnold, Gosling and Holmes. So whenever the various certification guides and mock exams disagree on terminology (or facts), I reach for TJPL. And for threads, TJPL must be consistent with Doug Lea. You can't go wrong with Lea. (His concurrent utilities will be a part of the Tiger Release of Java 1.5) So I also check Concurrent Programming in Java. In CCP 1.3.2 Liveness, Lea lists reasons a thread may fail to make progress. One reason is "CPU contention. A thread fails to run even though it is in a runnable state because other threads, or even completely separate programs running on the same computer, are occupying CPU or other computational resources." To me, that sounds like the thread is stopped. The VM is not executing the thread, the thread is not running, so it must be stopped. (If it were not stopped, then it is going. But this thread is not going anywhere.) TJPL and CCJ use the words blocked, paused, suspended and terminated. The 3 Sun e-Practice exams use the words blocked and terminated. I didn't see any use of stopped. On the exam I took, the way questions were asked was very reasonable. I wouldn't worry about ambiguous questions. [ February 02, 2004: Message edited by: Marlene Miller ]
Joined: Dec 05, 2003
I've never come across anyone describing a thread that is in ready state as a stopped thread before I started looking at Java. I just needed Java's view of what a stopped thread means. Thanks for your reply.