Example-2:Thread methods

Example-2: Thread methods


class Employee3 implements Runnable
{
int empId;
String empName;
@Override
public   void run() {
try {
for(int i=1;i<=3;i++)
{
System.out.println(Thread.currentThread().getName()+"\t"+Thread.currentThread().getId()+"\t"+empId+"\t"+empName+"\t"+Thread.currentThread().getPriority());
Thread.sleep(2000);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public class TestMethods {

public static void main(String a[])
{
System.out.println("Thread-Name"+"\t"+"Thread-Id"+"\t"+"Emp-Id"+"\t"+"Emp-Name"+"\t"+"Thread-Priority");
System.out.println("------------------------------------------------------------------------------------------------------------------------");
Employee3 employee1=new Employee3();
employee1.empId=1;
employee1.empName="a";
Thread thread1=new Thread(employee1);
thread1.setName("Employee-1");
thread1.setPriority(Thread.MIN_PRIORITY);
thread1.start();
Employee3 employee2=new Employee3();
employee2.empId=2;
employee2.empName="b";
Thread thread2=new Thread(employee2);
thread2.setName("Employee-2");
thread2.setPriority(Thread.MAX_PRIORITY);
thread2.start();
Employee3 employee3=new Employee3();
employee3.empId=3;
employee3.empName="c";
Thread thread3=new Thread(employee3);
thread3.setName("Employee-3");
thread3.setPriority(Thread.NORM_PRIORITY);
thread3.start();
Employee3 employee4=new Employee3();
employee4.empId=4;
employee4.empName="d";
Thread thread4=new Thread(employee4);
thread4.setName("Employee-4");
thread4.setPriority(2);
thread4.start();
/*Thread thread5=new Thread(employee3);
thread5.setName("Employee-5");
thread5.setPriority(11);//IllegalArguementException
thread5.start();*/
/*Thread thread6=new Thread(employee3);
thread6.setName("Employee-6");
thread6.setPriority(0);//IllegalArguementException
thread6.start();*/
/*Thread thread7=new Thread(employee3);
thread7.setName("Employee-7");
thread7.setPriority(-4);//IllegalArguementException
thread7.start();*/
}
}