Java thread deadlock code example
Deadlock is an error at the operating system level. It is the abbreviation of process deadlock. It was first proposed by Dijkstra when studying banker algorithm in 1965. It is one of the most difficult problems in computer operating system and even the whole field of concurrent programming.
In fact, many things in the computer world need to be solved by multithreading, because in this way, we can make the best use of resources and reflect the efficiency of computing. However, in fact, there are many resources that can only be used by one process at a time in the computer system, such as printers, and only one process can control it at the same time. In the multi-channel programming environment, several processes often share such resources, and a process may need more than one resource. Therefore, a number of processes will compete for limited resources and advance in an improper order, thus forming a situation of endless circular waiting. We call this state deadlock. To put it simply, deadlock refers to a situation in which multiple processes are deadlocked indefinitely while waiting for resources occupied by other parties. Obviously, if there is no external force, the processes involved in the deadlock will always be blocked.
File name: deadthreadbyextend java
Note:
1. The start method is used when starting the thread, and the run method can also be called, but it is only equivalent to an ordinary call, which is executed in the current thread.
2. Synchronized cannot directly modify variables.
3. Synchronized blocks do not force single threaded access to variables within the block. It only means that the synchronized (args) parameter is locked when executing the statement in the block and is not released until the end of execution.
summary
The above is all about the java thread deadlock code example in this article. I hope it will be helpful to you. If there are deficiencies, please leave a message to point out. Thank you for your support.