Friday, August 4, 2023

Thread class in Java - 6

 6. Priority

class ThreadPrio implements Runnable

{

Thread t;

ThreadPrio()

{

t=new Thread(this,"hello thread");

System.out.println(t);

t.start();

}

public void run()

{

System.out.println("hello thread started---");

try

{

Thread.sleep(1000);

}

catch(InterruptedException e)

{

}

System.out.println(t);

}

}

class T6Demo

{

public static void main(String args[])


{

ThreadPrio ob1=new ThreadPrio();

System.out.println("main thread "+Thread.currentThread());

ob1.t.setPriority(4);

}

}

o/p:------------------------------------------------------------------------------------------

ddmc@ddmc-desktop:~$ java T6Demo

Thread[hello thread,5,main]

hello thread started---

main thread Thread[main,5,main]

Thread[hello thread,4,main]

No comments:

Post a Comment

Complete Works of Swami Vivekananda [Volume 8,Page - 2069]

  Complete Works of Swami Vivekananda [ Volume 8, Page - 2069] Jesus Christ was God — the Personal God become man. He has manifested Himsel...