WAP to count the no. of times high and low priority threads loop run (extending thread class)
4 years ago
OOP Java
package threadpriority;
class NewThread extends Thread{
public long count;
NewThread(int priority)
{
setPriority(priority);
start();
}
public void run()
{ for(;;)
{ count++; }}
}
public class Count1 {
public static void main(String[] args) {
NewThread t1 = new NewThread(Thread.MIN_PRIORITY);
NewThread t2 = new NewThread(Thread.NORM_PRIORITY);
NewThread t3 = new NewThread(Thread.MAX_PRIORITY);
try{
Thread.sleep(3000);
}catch(InterruptedException ie)
{System.out.println("Main Thread Interrupted");}
System.out.println("Thread t1 count = "+t1.count);
System.out.println("Thread t2 count = "+t2.count);
System.out.println("Thread t3 count = "+t3.count);
}
}

Bijay Satyal
Nov 3, 2021