Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Threads,locks problem

 
anand phulwani
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Ranchers,


and the following instantiations:


Object obj1 = new Object();
Object obj2 = new Object();

obj1 and obj2 are accessible to two different threads and the threads are about to call the getLocks() method.
Assume the first thread calls the method getLocks(obj1, obj2).
Which of the following is true?
________________________________________________________________
a The second thread should call getLocks(obj2, obj1)
b The second thread should call getLocks(obj1, obj2)
c The second thread should call getLocks() only after first thread exits out of it.
d.The second thread may call getLocks() any time and passing parameters in any order.It should not call getLocks(obj2, obj1) because it may result in a deadlock.
e None of the above

Option B is correct
Is Anyone Having a explanation to this??

Thanks,
With Regds,
Anand
 
anand phulwani
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Ranchers,

Please Help me out on this question too.

Thanks,
With Regds,
Anand
 
Karu Raj
Ranch Hand
Posts: 481
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey anand

from where did you get this question
 
Jimmy Thomas
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Option B is correct
Is Anyone Having a explanation to this??


The reason is to avoid the possible problem of deadlocks. What option B ensures is that the order of locking remains the same.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic