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

Interference in Light vs Quantum States

🔬 The Double-Slit Experiment: Where It All Begins One of the most famous demonstrations of interference is the double-slit experiment. When...