This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread(suspend(), resume())

 
vinita Kh
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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");
suspend();
resume();
System.out.println("Leaving run");
}
public static void main(String args []) {
(new ThreadTest()).start();
}
}
 
Steven Wong
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it's because the thread can only be resumed by another thread, and not by itself.
Clement
 
Deepti Tewari
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
regards
Deepti
 
Shura Balaganov
Ranch Hand
Posts: 664
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Shura
[ May 04, 2002: Message edited by: Shura Balaganov ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic