Index Page : Link

Donate : Link

WordPress Blog : Link

  • If 2 threads are waiting for each other forever, such type of infinite waiting is called Deadlock.
  • Synchronized keyword is only reason for deadlock situation, hence while using Synchronized keyword we have to take special care.
  • There are no resolution technique for deadlock but several prevantion technique are available.
package com.example.thread;

Output :

Thread1 start execution of a1 method
Thread2 start execution of b1 method
Thread2 trying to call A's test()
Thread1 trying to call B's test()
  • In the above program if we remove atleast one synchronized keyword then program wouldn’t entered into deadlock. Hence synchronized keyword is only reason for deadlock situation. So due to this while using synchronized keyword we have to take special care.
  • Long waiting of a Thread where waiting never ends is called deadlock.
  • Whereas long waiting of a Thread where waiting ends at certain point is called starvation.
  • Ex. Law priority Thread has to wait until completing all high priority threads. It may be long waiting but ends at certain point which is nothing but starvation.