Write a program in java to demonstrate thread with thread name change?

class ThreadTest

{

      static

      {

            Thread t=Thread.currentThread();

            System.out.println("Name of current thread "+t.getName());

            System.out.println("Priority of thread is "+t.getPriority());

            try

            {

                  t.sleep(5000);

                  t.setName("Vikrant");

                  t.setPriority(420);

            }

            catch(Exception e)

            {

                  System.out.println(e);

            }

      }

      public static void main(String arg[])

      {

            System.out.println("main() is started");

            Thread t=Thread.currentThread();

            System.out.println("Name of current thread "+t.getName());

            System.out.println("Priority of thread is "+t.getPriority());

      }

}

thread with thread name change.PNG

, , , , , ,

Leave a Reply