javascript
Brief description  about Online courses   join in Online courses
View NELSON  THOMAS 's Profile

Threads

class Libin implements Runnable{
Thread T1;
public Libin(){
}public Libin(String Name){

T1=new Thread(this,Name);
T1.start();
}
public void run(){
System.out.println(Thread.currentThread());
}
}

public class Bijo{
public static void main(String[] args){
Thread S1=new Thread(new Libin(),"CT");
Thread S2=new Thread(new Libin(),"Chibanayil");
Libin d1=new Libin("class mate");

S1.start();
S2.start();
try{

System.out.println("The Name of the thread" Thread.currentThread());
Thread.currentThread().sleep(2000);

}catch (InterruptedException e){
System.out.println(" ");
}
}
}

1. In this program i get an output of this

Thread[class mate,5,main]
Thread[Chibanayil,5,main]
The Name of the threadThread[main,5,main]
Thread[CT,5,main]
is any problem in this output?,is it a genuine program the print statement of the main class is executed at third position,what is the reason please

help me

Asked by NELSON THOMAS | Feb 20, 2011 |  Reply now
Replies (2)
View nelson thomas 's Profile
Thank you sir
Feb 22, 2011
View arun kumar das 's Profile
Hi

its correct answer, thread is depending on computer when and which thread will execute first.

java teacher
Feb 22, 2011