Friday, April 7, 2017

What is Starvation and Livelock in Multithreading Java?

Starvation:

Starvation occurs when a single thread is perpetually access to a shared resource or lock.
The thread is active and unable to complete its work as a result of other threads constantly taking the resource that they trying to access.

Livelock:

Livelock occurs when two or more threads are conceptually blocked forever, although they
are each still active and trying to complete their task. Livelock is a special case of resource
starvation in which two or more threads actively try to acquire a set of locks, are unable to
do so, and restart part of the process.

Livelock is often a result of two threads trying to resolve a deadlock.

No comments: