class user extends Thread {
private Thread fth;
user(String name, Thread fth) {
super(name);
this.fth = fth;
}
public void run() {
System.out.println(this.getName());
try {
sleep(2000);
} catch (Exception e) {
// TODO: handle exception
throw new RuntimeException(e);
}
if (fth != null) {
try {
fth.join();
} catch (Exception e) {
}
System.out.println("NAME:" + this.getName() + "Bye");
}
}
}
class MT{
public static void main(String[] args) throws InterruptedException {
user u1=new user("1",null);
user u2=new user("2",u1);
user u3=new user("3",u2);
user u4=new user("4",u3);
u1.setPriority(Thread.MAX_PRIORITY);
u2.setPriority(Thread.MAX_PRIORITY-1);
u3.setPriority(Thread.MAX_PRIORITY-2);
u4.setPriority(Thread.MAX_PRIORITY-3);
u1.start();
u2.start();
u3.start();
u4.start();
}
}