/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
public class Main extends Thread{
public void run(){
try{
if(Thread.currentThread().getId()==11){
Thread.sleep(2000);
//System.out.println(Thread.currentThread().getState());
}
}
catch(InterruptedException e){
e.printStackTrace();
}
System.out.println("Thread is Running Id= "+Thread.currentThread().getId());
System.out.println("Thread is Running Name= "+Thread.currentThread().getName());
System.out.println("T2 "+Thread.currentThread().getState());
}
public static void main(String args[]){
// Creating object of thread class
Main thread=new Main(); //id=10 name=0
Main thread2= new Main(); //id=11 name=1
// Start the thread
System.out.println(thread.getState());
thread.setPriority(Thread.MIN_PRIORITY);
System.out.println(thread.getPriority());
System.out.println(thread2.getPriority());
thread.start();
System.out.println(thread.getState());
System.out.println(thread2.getState());
System.out.println(thread.activeCount());
thread2.start();
System.out.println("T2 "+thread2.getState());
System.out.println("T1 "+thread.getState());
System.out.println("T2 "+thread2.getState());
System.out.println("T1 "+thread.getState());
try
{
// waiting for thread t1 & t2 to complete its execution
thread.join();
thread2.join();
}
catch (InterruptedException ie)
{
ie.printStackTrace();
}
System.out.println("T1 "+thread.getState());
System.out.println("T2 "+thread2.getState());
}
}