import java.util.*; class ThreadDemo extends Thread { Thread t; String name; int priority; ThreadDemo(int priority,String name) { this.name=name; this.priority=priority; t=new Thread(this,name); System.out.println("New Thread "+t); t.start(); } public void run() { int p=t.getPriority(); try { if(p==9 || p==8) { t.sleep(2000); } else { System.out.println(t.currentThread()+"is alive?"+t.isAlive()); } while(t.isAlive()) { System.out.println("Long lasting thread:"+t.getName()); } } catch(InterruptedException ie) { System.out.println("Thread Interrupted...!"); } } } class MainThread { public static void main(String args[]) { //ThreadDemo a,b,c,d,e; new ThreadDemo(5,"One"); new ThreadDemo(6,"Two"); new ThreadDemo(7,"Three"); new ThreadDemo(8,"Four"); new ThreadDemo(9,"Five"); } }
8
9
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)