java.lang.management.ThreadInfo Class in Java Last Updated : 20 Jul, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report java.lang.management.ThreadInfo class contains methods to get information about a thread. This information includes: Thread IDThread NameState of the ThreadStack trace of the ThreadThe object upon which the Thread is blockedList of object monitors that are blocked by the ThreadList of ownable synchronizers blocked by the ThreadNumber of times the Thread had been blockedThe elapsed time for which the Thread had been blocked Syntax: Class declaration public class ThreadInfo extends Object The methods of this class are as follows: MethodsDescriptionThreadInfo from(CompositeData data)This method is used to represent this composite data as a ThreadInfo object.getBlockedCount()This method is used to know how many times the thread associated with this ThreadInfo object had been blocked to enter a monitor or reenter a monitor.getBlockedTime()This method is used to know for many milliseconds the thread associated with this ThreadInfo object had been blocked to enter or reenter a monitor.getLockedMonitors()This method is used to get a list of 'MonitorInfo' objects, which are currently locked by the thread associated with this ThreadInfo object.getLockedSynchronizers()This method is used to get a list of 'ownable' synchronizers, which are currently locked by the thread associated with this ThreadInfo object.getLockInfo()This method is used to get information about the object for which the thread associated with this ThreadInfo object is blocked waiting. It returns a 'LockInfo' object representing the information.getLockName()This method is used to get the name of the object for which the thread associated with this ThreadInfo object is blocked waiting.getLockOwnerId()This method is used to get the ID of the thread which owns the object that is blocking this thread.getLockOwnerName()This method is used to get the Name of the thread which owns the object that is blocking this thread.getStackTrace()This method is used to get the stack trace of a Thread.getThreadId()This method is used to get the ID of a Thread.getThreadName()This method is used to get the name of a Thread.getThreadState()This method is used to get the state of a Thread.getWaitedCount()This method is used to know how many times the thread associated with this ThreadInfo object has waited for notification.getWaitedTime()This method is used to know for many milliseconds the thread associated with this ThreadInfo object has waited for notification.isInNative()This method is used to determine whether this ThreadInfo object is executing the native code via the java native interface or not.isSuspended()This method is used to determine whether the Thread associated with this ThreadInfo object is suspended or not.toString()This method is used to get string representation of the given ThreadInfo object. Implementation: Example 1: Creating a new ThreadInfo object Java // Java Program to demonstrate ThreadInfo Class // Importing required libraries import java.lang.management.ManagementFactory; import java.lang.management.ThreadInfo; // Main class public class GFG { // main driver method public static void main(String[] args) { // Try block to check for exceptions try { // Creating a new thread by // creating an object of Thread class Thread thread = new Thread(); // running the thread using run() method thread.run(); // Getting thread id using getId() method long id = thread.getId(); // Creating a new ThreadInfo object // using that id ThreadInfo info = ManagementFactory.getThreadMXBean() .getThreadInfo(id); // Print and display message on the console System.out.println( "ThreadInfo object created successfully"); } // Catch block to handle the exceptions catch (Exception e) { // print the line number where exception occurs e.printStackTrace(); } } } Output: ThreadInfo object created successfully Example 2: Common-cleaner thread using ThreadInfo class Java // Java Program to demonstrate ThreadInfo Class // Importing required libraries import java.lang.management.ManagementFactory; import java.lang.management.ThreadInfo; // Main class public class GFG { // Main driver method public static void main(String[] args) { // try block to check for exceptions try { long id = 10; // Creating a new ThreadInfo object // using this id ThreadInfo info = ManagementFactory.getThreadMXBean() .getThreadInfo(id); // Printing information about the thread // 1. Printing thread id System.out.println("Thread ID: " + info.getThreadId()); // 2. Printing Thread Name System.out.println("Thread Name: " + info.getThreadName()); // 3. Printing thread State System.out.println("Thread State: " + info.getThreadState()); // 4. Printing thread waited count System.out.println("Waited count: " + info.getWaitedCount()); // 5. Printing thread waited time System.out.println("Waited time: " + info.getWaitedTime()); // 6. Printing how many times this thread had // been blocked System.out.println("Times blocked: " + info.getBlockedCount()); // 7. Printing Blocked duration System.out.println("Blocked duration: " + info.getBlockedTime()); // 8. Printing Locked Monitors System.out.println("Locked Monitors: " + info.getLockedMonitors()); // 9. Printing Locked Owner's ID System.out.println("Locked Owner's ID: " + info.getLockOwnerId()); // 10. Printing Locked Owner's Name System.out.println("Locked Owner's Name: " + info.getLockOwnerName()); } // Catch block to handle the exceptions catch (Exception e) { // Print the line number where exception occurred e.printStackTrace(); } } } Output: Thread ID: 10 Thread Name: Common-Cleaner Thread State: TIMED_WAITING Waited count: 1 Waited time: -1 Times blocked: 0 Blocked duration: -1 Locked Monitors: [Ljava.lang.management.MonitorInfo;@15aeb7ab Locked Owner's ID: -1 Locked Owner's Name: null Comment More infoAdvertise with us Next Article java.lang.management.ThreadInfo Class in Java A abhinavjain194 Follow Improve Article Tags : Java Java-lang package Practice Tags : Java Similar Reads Java Tutorial Java is a high-level, object-oriented programming language used to build web apps, mobile applications, and enterprise software systems. It is known for its Write Once, Run Anywhere capability, which means code written in Java can run on any device that supports the Java Virtual Machine (JVM).Java s 10 min read Java OOP(Object Oriented Programming) Concepts Java Object-Oriented Programming (OOPs) is a fundamental concept in Java that every developer must understand. It allows developers to structure code using classes and objects, making it more modular, reusable, and scalable.The core idea of OOPs is to bind data and the functions that operate on it, 13 min read Java Interview Questions and Answers Java is one of the most popular programming languages in the world, known for its versatility, portability, and wide range of applications. Java is the most used language in top companies such as Uber, Airbnb, Google, Netflix, Instagram, Spotify, Amazon, and many more because of its features and per 15+ min read Non-linear Components In electrical circuits, Non-linear Components are electronic devices that need an external power source to operate actively. Non-Linear Components are those that are changed with respect to the voltage and current. Elements that do not follow ohm's law are called Non-linear Components. Non-linear Co 11 min read Arrays in Java Arrays in Java are one of the most fundamental data structures that allow us to store multiple values of the same type in a single variable. They are useful for storing and managing collections of data. Arrays in Java are objects, which makes them work differently from arrays in C/C++ in terms of me 15+ min read Collections in Java Any group of individual objects that are represented as a single unit is known as a Java Collection of Objects. In Java, a separate framework named the "Collection Framework" has been defined in JDK 1.2 which holds all the Java Collection Classes and Interface in it. In Java, the Collection interfac 15+ min read Inheritance in Java Java Inheritance is a fundamental concept in OOP(Object-Oriented Programming). It is the mechanism in Java by which one class is allowed to inherit the features(fields and methods) of another class. In Java, Inheritance means creating new classes based on existing ones. A class that inherits from an 13 min read Spring Boot Tutorial Spring Boot is a Java framework that makes it easier to create and run Java applications. It simplifies the configuration and setup process, allowing developers to focus more on writing code for their applications. This Spring Boot Tutorial is a comprehensive guide that covers both basic and advance 10 min read Java Exception Handling Exception handling in Java allows developers to manage runtime errors effectively by using mechanisms like try-catch block, finally block, throwing Exceptions, Custom Exception handling, etc. An Exception is an unwanted or unexpected event that occurs during the execution of a program, i.e., at runt 10 min read Java Programs - Java Programming Examples In this article, we will learn and prepare for Interviews using Java Programming Examples. From basic Java programs like the Fibonacci series, Prime numbers, Factorial numbers, and Palindrome numbers to advanced Java programs.Java is one of the most popular programming languages today because of its 8 min read Like