Multi-threading and concurrency answers


Answer-1.[D] - Prints A B
Explanation - Thread main would keep on waiting until some other thread notify() it. So program won't terminate. But it would print A B as encountered before args.wait().

Answer-2.[D] - Runner quicker
Explanation - First it would call Runner class' constructor hence prints Runner. run() method calling rules are as follows:
First check inline run(), if it is there, it would be called.
Then check overridden run(), if it is there, it would be called.
Else, default run() which is present in Thread class would be called.

Answer-3.[A, F]
Explanation -
A : It is possible for more than two threads to deadlock at once. Consider a scenario where multiple threads are waiting for resource(s) in circular fashion, i.e. Thread A is waiting for resource locked by Thread B, B is waiting for resource locked by Thread C, C is waiting for resource locked by A.
C : Once sleep duration is expired for a particular thread, it only becomes runnable. Key point to note here is, While a thread goes to sleep or awakes as its sleep duration is expired, it keeps the lock(s) on resources held.

No comments:

Post a Comment