Hi!
I want to create two threads which run concurrently and I tried the following piece of code but when I run it the first
thread executes first and then the second one runs. Can you point out where I'm going wrong?
Thanks,
Sasikanth.
public class Threads3{
public static void main(
String args[]){
new th1();
new th2();
}
}
class th1 extends Thread{
public th1(){
System.out.println("creating an object of th1 class."+this);
start();
}
public void run()
{
for(int i=0;i<10;i++)
System.out.println("In thread1");
try{Thread.sleep(500);}
catch(InterruptedException e){System.out.println(e);}
}
}
class th2 extends Thread{
public th2(){
System.out.println("creating an object of th2 class."+this);
start();
}
public void run()
{
for(int i=0;i<10;i++)
System.out.println("In thread2");
try{Thread.sleep(500);}
catch(InterruptedException e){System.out.println(e);}
}
}