java7併發編程學習筆記

1.java線程狀態

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.
  • WAITING
    A thread that is waiting indefinitely for another thread to perform a particular action is in this state.
  • 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.
  • 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.


2.Thread.interrupted()靜態方法檢查當前線程是否中斷,並清除中斷狀態。  Thread實例的isInterrupted()方法只返回線程中斷狀態,推薦使用。


3.sleep()方法線程不會釋放對象鎖,wait()方法線程會放棄對象鎖。


4.兩種同步機制:synchronized關鍵字 和  Lock接口



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章