To get the state of a thread use getState()
method of a Thread
class. One thing to be noted is that this method is designed for use in monitoring of the system state, not for synchronization control.
package org.kodejava.lang;
public class GetThreadState implements Runnable {
public static void main(String[] args) {
Thread thread = new Thread(new GetThreadState());
thread.start();
// Get the state of the thread.
Thread.State state = thread.getState();
System.out.println("State: " + state.name());
}
public void run() {
System.out.println("Start..");
}
}
Latest posts by Wayan (see all)
- How do I get number of each day for a certain month in Java? - September 8, 2024
- How do I get operating system process information using ProcessHandle? - July 22, 2024
- How do I sum a BigDecimal property of a list of objects using Java Stream API? - July 22, 2024