The Java code demonstrates how to set the priority of a thread using the Thread.setPriority() method and then retrieve and print the priority using the Thread.getPriority() method. In the SetPriority class:
Thread priorities range from Thread.MIN_PRIORITY (1) to Thread.MAX_PRIORITY (10). The code sets the priority of the new thread to the maximum value of 10.
public class SetPriority { public static void main(String[] args) { Thread thread = new Thread(new MyRunnable()); thread.setPriority(Thread.MAX_PRIORITY); // Setting thread priority to maximum thread.start(); } static class MyRunnable implements Runnable { @Override public void run() { System.out.println("Thread priority: " + Thread.currentThread().getPriority()); } } }
Thread priority: 10
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions