The answer (Pram's), marked as correct, is not technically a dead end, as others have suggested. He was just blocked.
I would suggest in Java, you can rely on the definition of Java (which is consistent with the idea of two threads). The ultimate judge then can be the JVM if it detects a dead end itself . So, in the Pram example, the stream will show something like the following if it was a brilliant dead end.
Deadlock detected ================= "Negotiator-Thread-1": waiting to lock Monitor of com.google.code.tempusfugit.concurrency.DeadlockDetectorTest$Cat@ce4a8a which is held by "Kidnapper-Thread-0" "Kidnapper-Thread-0": waiting to lock Monitor of com.google.code.tempusfugit.concurrency.DeadlockDetectorTest$Cash@7fc8b2 which is held by "Negotiator-Thread-1"
This lock detection has been available for built-in locks with cyclic deadlocks with 1.5 and Lock since 1.6.
A permanently locked resource, or at least something that is waiting for something that will never happen, is called livelock . Similar problems, when processes outside the virtual machine (for example) stall databases, are quite possible, but I would not argue that this is not suitable for the question.
I would be interested to write how the interviewer claims that this is possible ...
In answer to your original question, for two tangos, I suggest that Pram's answer should not be marked as correct, because it did not exist! ;) The RMI thread that calls back can call but it works in a different thread (managed by the RMI server) than in the main one. Two threads are involved, even if the main thread has not explicitly set another. There is no deadlock, as evidenced by the absence of detection in the stream dump (or if you click "deadlock detection" in jconsole), it will be more accurately described as livelock.
Having said all this, any discussion in accordance with each of these answers would be enough to satisfy me as an interviewer.
Toby Dec 31 '10 at 15:26 2010-12-31 15:26
source share