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

SD Card vs SSD: What’s Really Happening Inside Your Storage

  We use SD cards in phones and cameras, and SSDs in laptops and PCs, almost without thinking. They both feel similar—fast, silent, and com...