import java.lang.*;
public class ThreadDemo {
public static void main(String[] args) {
Thread t1 = Thread.currentThread();
Thread t2 = Thread.currentThread();
Thread t3 = Thread.currentThread();
Thread t4 = Thread.currentThread();
Thread t5 = Thread.currentThread();
t1.setName("My Thread1");
t2.setName("My Thread2");
t3.setName("My Thread3");
t4.setName("My Thread4");
t5.setName("My Thread5");
t1.setPriority(6);
t2.setPriority(6);
t3.setPriority(6);
t4.setPriority(6);
t5.setPriority(7);
try
{
t3.sleep(2000);
t5.sleep(2000);
}
catch(Exception ex)
{
System.out.println("exception caught is"+ex);
}
System.out.println("Thread = " + t1);
System.out.println("Thread = " + t2);
System.out.println("Thread = " + t3);
System.out.println("Thread = " + t4);
System.out.println("Thread = " + t5);
int count = Thread.activeCount();
System.out.println("currently active threads = " + count);
}
}
public class ThreadDemo {
public static void main(String[] args) {
Thread t1 = Thread.currentThread();
Thread t2 = Thread.currentThread();
Thread t3 = Thread.currentThread();
Thread t4 = Thread.currentThread();
Thread t5 = Thread.currentThread();
t1.setName("My Thread1");
t2.setName("My Thread2");
t3.setName("My Thread3");
t4.setName("My Thread4");
t5.setName("My Thread5");
t1.setPriority(6);
t2.setPriority(6);
t3.setPriority(6);
t4.setPriority(6);
t5.setPriority(7);
try
{
t3.sleep(2000);
t5.sleep(2000);
}
catch(Exception ex)
{
System.out.println("exception caught is"+ex);
}
System.out.println("Thread = " + t1);
System.out.println("Thread = " + t2);
System.out.println("Thread = " + t3);
System.out.println("Thread = " + t4);
System.out.println("Thread = " + t5);
int count = Thread.activeCount();
System.out.println("currently active threads = " + count);
}
}
No comments:
Post a Comment