The provided Java code is correct and will display the priority of the current thread, which is the main thread in this case. Let's walk through the code:
As mentioned earlier, by default, the priority of the main thread is set to the priority of the thread that created it. In most cases, the default priority for all threads is Thread.NORM_PRIORITY, which has a value of 5.
public class ThreadPriority { public static void main(String[] args) { Thread thread = Thread.currentThread(); int priority = thread.getPriority(); System.out.println("Current Thread Priority: " + priority); } }
Current Thread Priority: 5
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions