• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Thread

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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( );
}
}
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic