Friday, April 12, 2019

thread suspend()/resume()

public class cl extends Thread{
 public void run(){
  for(int i=1;i<=3;i++){
   try{
    Thread.sleep(500);
   }catch(Exception e){System.out.println(e);}
  System.out.println(i);
  }
 }
public static void main(String args[]){
 cl t1=new cl();
 cl t2=new cl();
 cl t3=new cl();
 t1.start();
 t2.start();
 t3.start();
 }
}


$javac cl.java
$java -Xmx128M -Xms16M cl
1
1
1
2
2
2
3
3
3




public class cl extends Thread{ 
 public void run(){ 
  for(int i=1;i<=3;i++){ 
   try{ 
    Thread.sleep(500); 
   }catch(Exception e){System.out.println(e);} 
  System.out.println(i); 
  } 
 } 
public static void main(String args[]){ 
 cl t1=new cl(); 
 cl t2=new cl(); 
 cl t3=new cl(); 
 t1.start(); 
 t2.start(); 
 t2.suspend();
 t3.start(); 
 t2.resume();
 } 
}

No comments:

Post a Comment