public static enum Thread.State extends Enum<Thread.State> A thread state. A thread can be in one of the following states: NEW A thread that has not yet started is in this state. 创建,但没启动 RUNNABLE A thread executing in the Java virtual machine is in this state. 正在运行 BLOCKED A thread that is blocked waiting for a monitor lock is in this state. 阻塞,正在等待锁(临界资源)如:进入synchroinzed block方法或者重进入synchronize block方法, 注:java是支持重入reentrant 的。 WAITING A thread that is waiting indefinitely for another thread to perform a particular action is in this state. 等待,无限等待另一个线程执行一个特定动作 常见的如下: * <ul> * <li>{@link Object#wait() Object.wait} 但没有设置等待时间</li> * <li>{@link #join() Thread.join} 但没有设置等待时间</li> * <li>{@link LockSupport#park() 但没有设置等待时间}</li> * </ul> TIMED_WAITING A thread that is waiting for another thread to perform an action for up to a specified waiting time is in this state. * <ul> * <li>{@link #sleep Thread.sleep}</li> * <li>{@link Object#wait(long) Object.wait} with timeout</li> * <li>{@link #join(long) Thread.join} with timeout</li> * <li>{@link LockSupport#parkNanos LockSupport.parkNanos}</li> * <li>{@link LockSupport#parkUntil LockSupport.parkUntil}</li> * </ul> 定时等待 等待另一个线程执行,并设置了一个具体的等待时间(超时) TERMINATED A thread that has exited is in this state. A thread can be in only one state at a given point in time. These states are virtual machine states which do not reflect any operating system thread states. 终止, 线程已经退出执行时。 Since: 1.5
对比jstack反馈的线程状态
[root@localhost opt]# jstack 18984|grep Thread.State
java.lang.Thread.State: RUNNABLE
java.lang.Thread.State: RUNNABLE
java.lang.Thread.State: RUNNABLE
java.lang.Thread.State: RUNNABLE
java.lang.Thread.State: RUNNABLE
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: RUNNABLE
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: TIMED_WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: TIMED_WAITING (on object monitor)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: RUNNABLE
java.lang.Thread.State: BLOCKED (on object monitor)
java.lang.Thread.State: RUNNABLE
java.lang.Thread.State: BLOCKED (on object monitor)
java.lang.Thread.State: TIMED_WAITING (parking)
java.lang.Thread.State: WAITING (on object monitor)
java.lang.Thread.State: TIMED_WAITING (on object monitor)
java.lang.Thread.State: RUNNABLE
java.lang.Thread.State: RUNNABLE
java.lang.Thread.State: RUNNABLE
java.lang.Thread.State: RUNNABLE
java.lang.Thread.State: RUNNABLE
java.lang.Thread.State: RUNNABLE
java.lang.Thread.State: RUNNABLE
java.lang.Thread.State: RUNNABLE
java.lang.Thread.State: RUNNABLE
java.lang.Thread.State: RUNNABLE
java.lang.Thread.State: RUNNABLE
java.lang.Thread.State: RUNNABLE
java.lang.Thread.State: RUNNABLE
java.lang.Thread.State: RUNNABLE
java.lang.Thread.State: WAITING (on object monitor)
java.lang.Thread.State: WAITING (on object monitor)
jetty
"qtp458209687-970" #970 prio=5 os_prio=0 tid=0x00007fa8c001f000 nid=0x6df9 runnable [0x00007faa465e4000]
java.lang.Thread.State: RUNNABLE
at sun.nio.ch.EPollArrayWrapper.epollWait(Native Method)
at sun.nio.ch.EPollArrayWrapper.poll(EPollArrayWrapper.java:269)
at sun.nio.ch.EPollSelectorImpl.doSelect(EPollSelectorImpl.java:79)
at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:86)
- locked <0x00000005ca9b2b48> (a sun.nio.ch.Util$2)
- locked <0x00000005ca9b2b38> (a java.util.Collections$UnmodifiableSet)
- locked <0x00000005ca9b2910> (a sun.nio.ch.EPollSelectorImpl)
at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:97)
at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:101)
at org.eclipse.jetty.io.ManagedSelector$SelectorProducer.select(ManagedSelector.java:233)
at org.eclipse.jetty.io.ManagedSelector$SelectorProducer.produce(ManagedSelector.java:181)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceAndRun(ExecuteProduceConsume.java:171)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:156)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:654)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:572)
at java.lang.Thread.run(Thread.java:745)
上面的on object monitor 是等某个对象了,如object.wait
上面的parking,java 1.6 中LockSupport 有park方法,这个park主要是给上层提供更抽象的同步原语用的。
jstack会检查是否死锁,deadlock.
如果太多的BLOCKED,程序往往是陷入死锁或者饥饿了。
相关推荐
commons-lang3.3.1.jar、Apache Commons包中的一个,包含了一些数据类型工具类,是java.lang.*的扩展。必须使用的jar包。为JRE5.0+的更好的版本所提供 Jar文件包含的类: META-INF/MANIFEST.MFMETA-INF/LICENSE....
commons-lang3.3.1.jar、Apache Commons包中的一个,包含了一些数据类型工具类,是java.lang.*的扩展。必须使用的jar包。为JRE5.0+的更好的版本所提供 Jar文件包含的类: META-INF/MANIFEST.MFMETA-INF/LICENSE....
Java 5引入的枚举类型(如`java.lang.enum`)提供了一种安全的常量表示方式。 7. **System.in/err/out**:`System`类的静态变量`in`、`err`和`out`分别代表标准输入、错误输出和标准输出流,它们在I/O编程中扮演着...
org.apache.commons.lang.enum.Enum.class org.apache.commons.lang.enum.EnumUtils.class org.apache.commons.lang.enum.ValuedEnum.class org.apache.commons.lang.enums.Enum$Entry.class org.apache.commons....
在比较字符串与文字时,如果文字可以是一个字符串或Enum的元素,也可能会抛出java.lang.NullPointerException异常。例如: String str = null; if (str.equals("Test")) { // 这里将抛出java.lang....
枚举默认继承`java.lang.Enum`类,因此它们不能直接继承其他类,但可以实现接口。这使得枚举可以具有特定的行为。 6. **枚举常量的遍历** 可以通过for-each循环遍历枚举的所有实例,如: ```java for (Color ...
8. **多线程**:Java提供了丰富的多线程支持,`java.lang.Thread`类和`java.util.concurrent`包中的类和接口提供了创建和管理线程的方法。 9. **网络编程**:`java.net`包提供了网络通信的接口和类,如`Socket`和`...
在 Java 中,枚举类型可以使用 enum 关键字来定义。 在 Spring Boot 应用程序中,枚举类型经常被用于定义一些固定的值,例如订单状态、用户角色等。然而,在使用枚举类型时,需要注意一些坑,否则可能会出现一些...
5. **多线程编程**: `java.lang.Thread`和`java.util.concurrent`包提供了并发编程的基础设施。从Thread类到ExecutorService,开发者可以创建、管理和控制线程,以实现高效的并行处理。 6. **IO与NIO**: `java.io`...
"多线程"是Java的一个重要特性,java.lang.Thread类和java.util.concurrent包提供了线程的创建和管理。"网络编程"涉及java.net包,如Socket和ServerSocket,可用于建立客户端和服务器之间的连接。此外,"异常处理"...
- 枚举类型自动继承自`java.lang.Enum`类,这意味着它们可以直接使用`Enum`类提供的方法,而无需显式地继承。 2. **枚举的好处:** - **安全性**:确保了变量只能赋值为预定义的一组值之一。 - **编译时检查**:...
6. **多线程(Multithreading)**:Java API提供了丰富的多线程支持,包括`java.lang.Thread`类和`java.util.concurrent`包中的高级并发工具。 7. **I/O流(Input/Output Stream)**:Java的I/O系统由`java.io`包...
Java SE程序 Enum枚举类Java SE程序 Enum枚举类Java SE程序 Enum枚举类Java SE程序 Enum枚举类Java SE程序 Enum枚举类Java SE程序 Enum枚举类Java SE程序 Enum枚举类Java SE程序 Enum枚举类Java SE程序 Enum枚举类...
计算机后端-Java-Java核心基础-第23章 枚举类与注解 06. 使用enum关键字定义枚举类.avi
4. **多线程**:`java.lang.Thread`和`java.util.concurrent`包为多线程编程提供了支持。`Thread`类代表了程序中的一个执行线程,而`java.util.concurrent`提供了并发工具类,如`ExecutorService`和`Future`,便于...
计算机后端-Java-Java核心基础-第23章 枚举类与注解 08. 使用enum关键字定义的枚举类实
return Enum.valueOf(Color.class, name); } } ``` ##### 3. 构造函数 枚举类的构造函数是私有的,并且默认有一个参数化的构造函数。例如: ```java enum Color { RED(255, 0, 0), BLUE(0, 0, 255), BLACK(0, 0,...
- `BIGINT`: 用来存储大整数,对应 Oracle 的 `NUMBER(19,0)`,Java 中可使用 `java.lang.Long` 对应。 - `BIT`: 存储位数据,Oracle 没有直接对应的数据类型,通常使用 `RAW` 类似。 - `BLOB`: 用于存储大对象,...
5. **多线程**:`java.lang.Thread`和`java.util.concurrent`包提供了多线程支持,包括线程的创建、同步和管理。`synchronized`关键字和`java.util.concurrent.locks`包中的锁机制是实现线程安全的关键。 6. **日期...
在这里,`Color`是枚举类型,`RED`, `GREEN`, `BLUE`是枚举的实例,它们默认继承自`java.lang.Enum`类。 2. 访问枚举实例: 你可以通过枚举类型直接访问其实例,例如: ```java Color color = Color.RED; ``` 3. ...