Troubleshooting #
Alongside race conditions, there are several reasons why a program that uses multithreading may not behave as intended.
Two common ones are deadlocks and (to a lesser extent) starvation.
Deadlock #
Terminology. A deadlock occurs when two threads wait for each other to release a (different) lock.
This notion also generalizes to cyclic deadlocks involving more than two threads.
In Java, this may be caused by synchronized methods or statements. An illustration can be found here.
Starvation #
A thread is starving if it does not get regular access to a shared resource, and as a result cannot progress in its execution.
This situation can often be avoided with a queue.