Thread相關學習之二 - JavaThread&JVMTIThread的生命週期
執行緒生命週期
JavaThread生命週期
執行緒生命週期就在上述的6個狀態中流轉,如下圖:
JVMTIThreadState定義
不過在jvmti.xml中,看到了jvmti(JVM Tool Interface)定義的相關ThreadState,看下:
<constants id="jvmtiThreadState" label="Thread State Flags" kind="bits">
<constant id="JVMTI_THREAD_STATE_ALIVE" num="0x0001">
Thread is alive. Zero if thread is new (not started) or terminated.
</constant>
<constant id="JVMTI_THREAD_STATE_TERMINATED" num="0x0002">
Thread has completed execution.
</constant>
<constant id="JVMTI_THREAD_STATE_RUNNABLE" num="0x0004">
Thread is runnable.
</constant>
<constant id="JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER" num="0x0400">
Thread is waiting to enter a synchronization block/method or,
after an <code>Object.wait()</code>, waiting to re-enter a
synchronization block/method.
</constant>
<constant id="JVMTI_THREAD_STATE_WAITING" num="0x0080">
Thread is waiting.
</constant>
<constant id="JVMTI_THREAD_STATE_WAITING_INDEFINITELY" num="0x0010">
Thread is waiting without a timeout.
For example, <code>Object.wait()</code>.
</constant>
<constant id="JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT" num="0x0020">
Thread is waiting with a maximum time to wait specified.
For example, <code>Object.wait(long)</code>.
</constant>
<constant id="JVMTI_THREAD_STATE_SLEEPING" num="0x0040">
Thread is sleeping -- <code>Thread.sleep(long)</code>.
</constant>
<constant id="JVMTI_THREAD_STATE_IN_OBJECT_WAIT" num="0x0100">
Thread is waiting on an object monitor -- <code>Object.wait</code>.
</constant>
<constant id="JVMTI_THREAD_STATE_PARKED" num="0x0200">
Thread is parked, for example: <code>LockSupport.park</code>,
<code>LockSupport.parkUtil</code> and <code>LockSupport.parkNanos</code>.
</constant>
<constant id="JVMTI_THREAD_STATE_SUSPENDED" num="0x100000">
Thread suspended.
<code>java.lang.Thread.suspend()</code>
or a <jvmti/> suspend function
(such as <functionlink id="SuspendThread"></functionlink>)
has been called on the thread. If this bit
is set, the other bits refer to the thread state before suspension.
</constant>
<constant id="JVMTI_THREAD_STATE_INTERRUPTED" num="0x200000">
Thread has been interrupted.
</constant>
<constant id="JVMTI_THREAD_STATE_IN_NATIVE" num="0x400000">
Thread is in native code--that is, a native method is running
which has not called back into the VM or Java programming
language code.
<p/>
This flag is not set when running VM compiled Java programming
language code nor is it set when running VM code or
VM support code. Native VM interface functions, such as JNI and
<jvmti/> functions, may be implemented as VM code.
</constant>
<constant id="JVMTI_THREAD_STATE_VENDOR_1" num="0x10000000">
Defined by VM vendor.
</constant>
<constant id="JVMTI_THREAD_STATE_VENDOR_2" num="0x20000000">
Defined by VM vendor.
</constant>
<constant id="JVMTI_THREAD_STATE_VENDOR_3" num="0x40000000">
Defined by VM vendor.
</constant>
</constants>
可以看到,這裡使用十六進位制表示一個具體的ThreadState值。整理一下:
Thread State Flags | ||
---|---|---|
Constant | Value | Description |
JVMTI_THREAD_STATE_ALIVE |
0x0001 | Thread is alive. Zero if thread is new (not started) or terminated. |
JVMTI_THREAD_STATE_TERMINATED |
0x0002 | Thread has completed execution. |
JVMTI_THREAD_STATE_RUNNABLE |
0x0004 | Thread is runnable. |
JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER |
0x0400 | Thread is waiting to enter a synchronization block/method or, after an Object.wait() , waiting to re-enter a synchronization block/method. |
JVMTI_THREAD_STATE_WAITING |
0x0080 | Thread is waiting. |
JVMTI_THREAD_STATE_WAITING_INDEFINITELY |
0x0010 | Thread is waiting without a timeout. For example, Object.wait() . |
JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT |
0x0020 | Thread is waiting with a maximum time to wait specified. For example, Object.wait(long) . |
JVMTI_THREAD_STATE_SLEEPING |
0x0040 | Thread is sleeping -- Thread.sleep(long) . |
JVMTI_THREAD_STATE_IN_OBJECT_WAIT |
0x0100 | Thread is waiting on an object monitor -- Object.wait . |
JVMTI_THREAD_STATE_PARKED |
0x0200 | Thread is parked, for example: LockSupport.park , LockSupport.parkUtil and LockSupport.parkNanos . |
JVMTI_THREAD_STATE_SUSPENDED |
0x100000 | Thread suspended. java.lang.Thread.suspend() or a JVM TI suspend function (such as [SuspendThread ](file:///home/alanjin/gitspace/jdk10/hotspot/src/share/vm/prims/jvmti.xml#SuspendThread)) has been called on the thread. If this bit is set, the other bits refer to the thread state before suspension. |
JVMTI_THREAD_STATE_INTERRUPTED |
0x200000 | Thread has been interrupted. |
JVMTI_THREAD_STATE_IN_NATIVE |
0x400000 | Thread is in native code--that is, a native method is running which has not called back into the VM or Java programming language code. This flag is not set when running VM compiled Java programming language code nor is it set when running VM code or VM support code. Native VM interface functions, such as JNI and JVM TI functions, may be implemented as VM code. |
JVMTI_THREAD_STATE_VENDOR_1 |
0x10000000 | Defined by VM vendor. |
JVMTI_THREAD_STATE_VENDOR_2 |
0x20000000 | Defined by VM vendor. |
JVMTI_THREAD_STATE_VENDOR_3 |
0x40000000 | Defined by VM vendor. |
注意其中的值都是16進位制資料,而實際上是用位(bit)來組合計算的。
相關文章
- 學習vue生命週期Vue
- View生命週期與Activity生命週期的關係View
- vue生命週期整理學習Vue
- React生命週期學習筆記React筆記
- Angular學習(二):元件-生命週期Angular元件
- ReactJS前端學習-元件生命週期ReactJS前端元件
- 品牌生命週期和產品生命週期之間的關係
- Vue學習(三)生命週期函式Vue函式
- Vue學習筆記(2)—— Vue的生命週期Vue筆記
- Java開發學習(五)----bean的生命週期JavaBean
- EntityFramework 學習【Entity Lifecycle 實體生命週期】Framework
- Vue原始碼學習(八):生命週期呼叫Vue原始碼
- rust學習十一.3、生命週期標記Rust
- Mybatis學習-配置、作用域和生命週期MyBatis
- 用Flutter做APP學習心得:Flutter widget的生命週期FlutterAPP
- flutter學習日記(三)————Flutter的生命週期和路由Flutter路由
- 前端學習(2369):元件的建立使用和元件的生命週期前端元件
- 生命週期
- Spring中與bean有關的生命週期SpringBean
- 關於Spring生命週期控制的介面:SmartLifecycleSpring
- viewController的生命週期ViewController
- Servlet的生命週期Servlet
- UIViewController的生命週期UIViewController
- Flutter 的生命週期Flutter
- Spring的生命週期Spring
- bean的生命週期Bean
- SQL的生命週期SQL
- Laravel的生命週期Laravel
- 類的生命週期
- iOS初級開發學習筆記:APP生命週期的學習總結iOS筆記APP
- angular4學習記錄 — 元件通訊、生命週期Angular元件
- vue - 生命週期第二次學習與理解Vue
- vue - 生命週期Vue
- Fragment生命週期Fragment
- vue生命週期Vue
- spring生命週期Spring
- ubuntu生命週期Ubuntu
- Flutter - 生命週期Flutter