Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread

 
suren r
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
I am new to Java programming,I need help from you guys..
I saw this question in mock exam and I though the answer is
"starting" and "done",but it's printing only"starrting"..where as if I replace yield()in place of suspend()it is printing both..
I remember reading some where suspended threads canbe restarted..
if that is the case why it is not printing both words..
Thanks in advance.....
here is the program
class demo1 extends Thread {
public void run( ) {
System.out.println("Starting");
suspend( );
resume( );
System.out.println("Done");
}
public static void main(String args[ ]) {
demo1 tt = new demo1( );
tt.start( );
}
}
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When your demo1 Thread executes suspend, it suspends itself.
There exists no running Thread to execute resume so it stays suspended indefinately.
Both suspend and resume are deprecated methods of Thread. You should not be using them because they can easily lead to deadlock situations.
Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic