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 Thread(suspend(), resume()) 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 "Thread(suspend(), resume())" Watch "Thread(suspend(), resume())" New topic

Thread(suspend(), resume())

vinita Kh
Ranch Hand

Joined: Feb 19, 2002
Posts: 49
y the output of this code only "In run"
& not also "Leaving run" ie.ones this thread is suspended, y it never resumes()
public class ThreadTest extends Thread {
public void run() {
System.out.println("In run");
System.out.println("Leaving run");
public static void main(String args []) {
(new ThreadTest()).start();
Steven Wong
Ranch Hand

Joined: Mar 07, 2002
Posts: 295
I think it's because the thread can only be resumed by another thread, and not by itself.

best regards,<br />Steven<br />SCJP, SCEA
Deepti Tewari

Joined: Mar 21, 2002
Posts: 14
Hi Vinita,
I agreee with Clemet.
Once you have called suspend() the thread stops running and resume method is never called.
and thus the print statement after resume is never executed.
Shura Balaganov
Ranch Hand

Joined: Apr 22, 2002
Posts: 664
This code doesn't even compile with 1.4 compiler on Win2K. Compiler errors: suspend() and resume() have been deprecated.
Correction, it will compile with a -deprecation flag.
Does it mean it is still possible for question like this to appear on SCJP2 exam?
[edit: comments below]
If you use yield() instead of suspend(), it will print both lines and exit successfully.
[ May 04, 2002: Message edited by: Shura Balaganov ]

Any posted remarks that may or may not seem offensive, intrusive or politically incorrect are not truly so. - Russian America today - Guide To Russia
I agree. Here's the link:
subject: Thread(suspend(), resume())
It's not a secret anymore!