DEMO
package thread;
import java.util.concurrent.TimeUnit;
public class ThreadStatusDemo {
public static void main(String[] args) {
new Thread(new Runnable() {
public void run() {
while (true) {
try {
TimeUnit.SECONDS.sleep(150);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
},"TIME_WAITING_THREAD").start();
new Thread(new Runnable() {
public void run() {
while (true) {
synchronized (ThreadStatusDemo.class) {
try {
ThreadStatusDemo.class.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
},"WAITING_THREAD").start();
new Thread(new BlockedDemo(),"BLOCKED_THREAD01").start();
new Thread(new BlockedDemo(),"BLOCKED_THREAD02").start();
}
static class BlockedDemo extends Thread{
@Override
public void run() {
synchronized (BlockedDemo.class) {
while (true) {
try {
TimeUnit.SECONDS.sleep(150);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
}
}
结果
控制台运行jps查看运行的程序pid

输入java自带的命令jstack pid查看线程状态
