Witshaper is the Professional (Computing Skills, English Learning and Soft Skills) Skill Development Training Center. We provide Professional IT Courses and Soft Skill Training in Dehradun to Students, Employees and organization. Who wish to pursue a career in IT Technology. Witshaper is led by a motivated team of IT experts and Soft Skill Professionals. We provide high quality trainings. Our Emphasis is on giving the practical knowledge to the students, so that they will get to know in depth and never forget what they opt, we provide to the students real learning environment. Witshaper prepares students and professionals to be the part of this growing industry. Be a part of Witshaper and get your dreams successful

Wednesday, 20 May 2015

java program to create thread and set priority ,id,and name

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);
   }
}

No comments:

Post a Comment