• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Threads,locks problem

 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Ranchers,

Please Help me out on this question too.

Thanks,
With Regds,
Anand
 
Ranch Hand
Posts: 481
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey anand

from where did you get this question
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic