• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

suspend() and resume()

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
please read this code :
class a {
public static void main(String agrs[]){
System.out.println("Begin ");
suspend();
resume();
System.out.println("End ");
}
}
the answer printed is
Begin
and then the system hangs as it is suspended by suspend command
but why it is not called back by resume.
tell me how the resume functions(through object calls or whatever).
how to print both Begin and End ?
 
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A suspended thread cannot resume itself. Some other thread that has got the permission (the thread belonging to the same ThreadGroup) must start this suspended thread.
Here is the code that prints Begin ... End :

HTH
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi amit
In the program there is only one thread main.
If u suspend this thread and resume means it waits for another thread to execute, that why it wont print END.
If u create one more thread, then it prints both like

class a extends Thread{
public a(){
Thread t1= new Thread(this);
t1.start();
}
public void run(){
this.suspend();
System.out.println("Begin ");
System.out.println("End ");
}
public static void main(String agrs[]){
a t2 = new a();
Thread t=Thread.currentThread();
t.resume();
}
}

Srinivas
 
Ranch Hand
Posts: 3143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Srinivas V,
Your contribution to Javaranch is very important to us.
However we do have a naming policy outlined here.
Please register again with a name which complies to this rule.
Otherwise I'm afraid you may come to the Ranch soon and find that your account has been locked.
Thank You.
[This message has been edited by Angela Poynton (edited December 08, 2000).]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic