线程状态

Thread.State

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.(运行状态:start()`方法被调用,但线程可能处于就绪(等待被调度)或正占用着CPU在运行。
  • BLOCKED
    ​ A thread that is blocked waiting for a monitor lock is in this state.(线程在进入同步块或获取监视器锁前的等待状态)
  • WAITING
    ​ A thread that is waiting indefinitely for another thread to a particular action is in this state.(线程之前持有监视器锁,并正在临界区执行,在锁上调用wait()方法后,等待其它线程唤醒的状态)
  • TIMED_WAITING
    ​ A thread that is waiting for another thread to perform an action up to a specified waiting time is in this state.(超时等待,线程的在此执行并不完全取决于其它线程的唤醒,当达到超时时间后,自行恢复)
  • 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

通过_VisualVM_监控某个时刻的线程运行状况:


2016-10-11 22:08:13
Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.101-b13 mixed mode):

"00000BlockingThread-2" #14 prio=5 os_prio=0 tid=0x0000000018b4d800 nid=0x2494 waiting for monitor entry [0x000000001ad1f000]
   java.lang.Thread.State: BLOCKED (on object monitor)
	at thread.ThreadState$Blocked.run(ThreadState.java:45)
	- waiting to lock <0x00000000d5e5f050> (a java.lang.Class for thread.ThreadState$Blocked)
	at java.lang.Thread.run(Unknown Source)

   Locked ownable synchronizers:
	- None

"00000BlockingThread-1" #13 prio=5 os_prio=0 tid=0x0000000018b49000 nid=0x1f54 waiting on condition [0x000000001ae5f000]
   java.lang.Thread.State: TIMED_WAITING (sleeping)
	at java.lang.Thread.sleep(Native Method)
	at java.lang.Thread.sleep(Unknown Source)
	at java.util.concurrent.TimeUnit.sleep(Unknown Source)
	at thread.SleepUtils.second(SleepUtils.java:8)
	at thread.ThreadState$Blocked.run(ThreadState.java:45)
	- locked <0x00000000d5e5f050> (a java.lang.Class for thread.ThreadState$Blocked)
	at java.lang.Thread.run(Unknown Source)

   Locked ownable synchronizers:
	- None

"00000WaitingThread" #12 prio=5 os_prio=0 tid=0x0000000018b48800 nid=0x1210 in Object.wait() [0x000000001aa7f000]
   java.lang.Thread.State: WAITING (on object monitor)
	at java.lang.Object.wait(Native Method)
	- waiting on <0x00000000d5e5d790> (a java.lang.Class for thread.ThreadState$Waiting)
	at java.lang.Object.wait(Unknown Source)
	at thread.ThreadState$Waiting.run(ThreadState.java:29)
	- locked <0x00000000d5e5d790> (a java.lang.Class for thread.ThreadState$Waiting)
	at java.lang.Thread.run(Unknown Source)

   Locked ownable synchronizers:
	- None

"00000TimeWaitingThread" #11 prio=5 os_prio=0 tid=0x0000000018b45800 nid=0xd44 waiting on condition [0x000000001a08e000]
   java.lang.Thread.State: TIMED_WAITING (sleeping)
	at java.lang.Thread.sleep(Native Method)
	at java.lang.Thread.sleep(Unknown Source)
	at java.util.concurrent.TimeUnit.sleep(Unknown Source)
	at thread.SleepUtils.second(SleepUtils.java:8)
	at thread.ThreadState$TimeWaiting.run(ThreadState.java:16)
	at java.lang.Thread.run(Unknown Source)

   Locked ownable synchronizers:
	- None

"Service Thread" #10 daemon prio=9 os_prio=0 tid=0x0000000018adf800 nid=0x238c runnable [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

   Locked ownable synchronizers:
	- None

"C1 CompilerThread3" #9 daemon prio=9 os_prio=2 tid=0x0000000018a3b000 nid=0x2528 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

   Locked ownable synchronizers:
	- None

"Signal Dispatcher" #4 daemon prio=9 os_prio=2 tid=0x0000000018a28000 nid=0x2254 runnable [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

   Locked ownable synchronizers:
	- None

"Finalizer" #3 daemon prio=8 os_prio=1 tid=0x000000001795f800 nid=0x2434 in Object.wait() [0x0000000019acf000]
   java.lang.Thread.State: WAITING (on object monitor)
	at java.lang.Object.wait(Native Method)
	- waiting on <0x00000000d5d08ee0> (a java.lang.ref.ReferenceQueue$Lock)
	at java.lang.ref.ReferenceQueue.remove(Unknown Source)
	- locked <0x00000000d5d08ee0> (a java.lang.ref.ReferenceQueue$Lock)
	at java.lang.ref.ReferenceQueue.remove(Unknown Source)
	at java.lang.ref.Finalizer$FinalizerThread.run(Unknown Source)

   Locked ownable synchronizers:
	- None

"VM Thread" os_prio=2 tid=0x0000000017951800 nid=0x2748 runnable 

"GC task thread#0 (ParallelGC)" os_prio=0 tid=0x000000000232c800 nid=0x2350 runnable 

"VM Periodic Task Thread" os_prio=2 tid=0x0000000018b35800 nid=0x1448 waiting on condition 

JNI global references: 349

thread state

posted @ 2017-01-31 00:11  JintaoXIAO  阅读(180)  评论(0编辑  收藏  举报