Multithreading state

1, the initial state

2, operating status

3, blocking state

4, wait state

5, the timeout wait state

6, termination status

 

 

sleep() VS wait()

The main difference between the two:

  1. sleep () method is a static method of the Thread, and wait method is an example of Object
  2. wait () method must be called synchronization or sync blocks method, i.e. must have an object lock. The sleep () method does not have this limitation can be used anywhere species. In addition, wait () method will release the possession of the object lock, so that the thread into the wait pool, access to resources waiting for the next. The sleep () method simply makes the CPU does not release the object lock out;
  3. After the sleep () method to get CPU time slice if again will resume when the sleep time is reached while the wait () method must wait Object.notift / Object.notifyAll notice, will leave the waiting pool, and get CPU time slice again before We will continue.

Daemon thread on exit and does not execute code finnaly block, it will free up resources and other operations not on finnaly block execution of this operation is unsafe

 

Guess you like

Origin www.cnblogs.com/zquan/p/11279915.html