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接口