Friday, April 12, 2019

multithreading with run()

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



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

No comments:

Post a Comment