Simple java program to create Deadlock.
Deadlock describes a situation where two or more threads are blocked forever, waiting for each other.
Let's consider an example, in the office we have shared Printer and Scanner where Employees has ability to do scanning and printing.
1. John has bunch of documents that it wants to Print first and also want to take a Scan later.
(Print and Scan)
2. Michael has bunch of documents that it wants to Scan first and also want to take a Print later.
(Scan and Print)
Difference between process and thread.
A process is an executing instance of an application.
Thread is independent path of execution within a process. Process can have multiple threads,
Threads itself is capable enough to do all the things a process does and thread is a part of process that is why thread can be termed as light-weight process.
Since all the Threads are part of a same Process they all share same memory allocated by Process.
Process use memory allocated by OS.
Inter-thread communication between threads is easy whereas Inter-process communication is difficult.
Processes have independent data and code segments.
Thread shares the data segment, code segment, files etc. with its peer threads.
Process switching is complex as compared to thread switching because of the amount of variables need to be maintained in both of the case.
|Per process items||Per thread items|
|Address space||Program counter|
|Signals and signal handlers|
You may also like to see
If you find any issue in post or face any error while implementing, Please comment.