The code you've provided is correct and demonstrates how to obtain various information about the current executing thread in Java. It uses methods provided by the Thread class to access information such as the thread's name, ID, priority, state, daemon status, liveness, and interruption status. Your code is a useful example of how to retrieve and display thread information in a Java program. Here's a breakdown of what the code does:
public class CurrentThreadInfo { public static void main(String[] args) { // Get the current executing thread Thread currentThread = Thread.currentThread(); // Print thread information System.out.println("Thread Name : " + currentThread.getName()); System.out.println("Thread ID : " + currentThread.getId()); System.out.println("Thread Priority : " + currentThread.getPriority()); System.out.println("Thread State : " + currentThread.getState()); System.out.println("Thread is Daemon : " + currentThread.isDaemon()); System.out.println("Thread is Alive : " + currentThread.isAlive()); System.out.println("Thread is Interrupted : " + currentThread.isInterrupted()); } }
Thread Name : main Thread ID : 1 Thread Priority : 5 Thread State : RUNNABLE Thread is Daemon : false Thread is Alive : true Thread is Interrupted : false
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions