Deadlock (DeadLock)
Overview deadlock
thread deadlock refers to two or more of the other threads hold resources needed each other, due to the characteristics of synchronized, one thread holds a resource, or to obtain a lock, the lock is released before the thread other threads are not obtain the lock, and the wait would have been dead, so this will cause a deadlock.
Conditions Deadlock
Mutually exclusive conditions: a resource or a lock can only be occupied by a thread after a first thread to acquire the lock until the thread releases the lock, other threads are unable to get to the lock.
Possession and waiting for: a thread has to acquire a lock, then get another lock in the process, even if it will not get less than the lock release has been obtained.
Inalienable condition: any thread can not be forced to get another thread already has a lock
Loop wait condition: Thread A Thread B holds the lock, the lock holding thread A thread B. .
How to avoid deadlocks
Locking sequence: thread locking in the same order.
Locking time, the process thread to acquire a lock in a certain time limit, if not given time to obtain, even, do not force yourself. This need to use some of the API Lock.
Deadlock Detection
After a deadlock occurs, the program got stuck and nothing happens, but the program is still running, and therefore need the help of some
The first to use jps -l displays a virtual machine running processes and displays (main function where the virtual machine executes the main class of
the class) as well as the name of a local virtual machine these processes unique ID