Wednesday, August 22, 2012

Thread Example in Java


public class ThreadExample extends Thread{

public synchronized  void run(){
for(int i=0;i<11;i++)
System.out.print(i);
System.out.println(" ");
}
public static void main(String args[]){
Thread t1=new ThreadExample();
Thread t2=new ThreadExample();
Thread t3=new ThreadExample();

t1.start();
t2.start();
t3.start();

t1.setPriority(MAX_PRIORITY);
System.out.println("Thread 1 Priority"+t1.getPriority());

System.out.println("Thread 1 Group"+t1.getThreadGroup());

System.out.println("State of Thread2"+t2.getState());

}
}

No comments:

Post a Comment

Thanks for your valuable comments