-1

Suppose a thread acquires reentrant lock on a resource multiple times and dies. What will happen to the resource? Can another client access the resource?

a3.14_Infinity
  • 5,653
  • 7
  • 42
  • 66

2 Answers2

3

Proof by demonstration:

public static void main(String[] args) throws InterruptedException {
  final ReentrantLock lock = new ReentrantLock();
  final Thread t = new Thread(()->lock.lock());
  t.start();
  t.join();
  System.out.println(t.isAlive());
  System.out.println(lock.tryLock());
}

It prints

false
false
Marko Topolnik
  • 195,646
  • 29
  • 319
  • 436
0

Sounds like a classical deadlock to me. If the lock is not released by the owner - it will stay locked for ever and for everyone.

light_303
  • 2,101
  • 2
  • 18
  • 35