Write a program in java to demonstrate user thread in using direct way?

class ThreadWay implements Runnable

{

      static

      {

            Thread t=Thread.currentThread();

            System.out.println(t.getName());

      }

      public void run()

      {

            Thread t=Thread.currentThread();

            System.out.println(t.getName());

            System.out.println("Task 1");

      }

}

class Direct

{

      public static void main(String arg[])

      {

            ThreadWay x=new ThreadWay();

            Thread t1=new Thread(x);

            Thread t2=new Thread(x);

            t1.start();

            t2.start();

      }

}

Direct

, , , , , ,

Leave a Reply