What might cause the current thread to stop executing? A. An InterruptedException is thrown B. The thread executes a sleep() call C. The thread constructs a new Thread D. A thread of higher priority becomes ready (runnable) E. The thread executes a read() call on an InputStream ans:B,D,E can anybody explain why A is wrong & E is correct
2:Which statements are true about threads? A. Threads created from the same class all finish together B. A thread can be created only by subclassing Java.Lang.Thread. C. Invoking the suspend() stops a thread so that it cannot be restarted D. The Java Interpreter's natural exit occurs when no non daemon threads remain alive E. Uncoordinated changes to shared data by multiple threads may result in the data being read, or left, in an inconsistent state. MY ANS:CDE. ans given are E why ans C is incorrect? pls help thanx sherinn
With regard to question 2 C. Invoking the suspend() stops a thread so that it cannot be restarted and Why C is not correct, this is what the Java 2 Certification by 'Jamie Jaworski' says, and I am curious if it is correct or not. 'Prior to JDK 1.2, it was possible for one thread to stop or suspend the execution of another thread(or itself). The stop(), suspend(), and resume() methods have been identified as problematic and are deprecated in JDK 1.2' According to that statement, C is not correct because the methods are no longer supported? Can anybody set us straight on this, it would concern me if my study guide had errors as bad as this. Thanks Guy
With question 1 I see A as incorrect because the question asks what could CAUSE a thread to stop executing, the InterruptedException is thrown as a result of a thread being interrupted, the exception did not cause the thread to stop executing, it would be a statement like interrupt().
For question 1) (A) is wrong because thread is already in the wait mode when this exception occurs. (E) is right beacuse read() puts the thread in a blocked state. For question 2) (C) is wrong because because another thread can start the suspended thread. (D) seems to be right for me. Please do give comments on these.