aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Threads,locks problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Threads,locks problem" Watch "Threads,locks problem" New topic
Author

Threads,locks problem

anand phulwani
Ranch Hand

Joined: Sep 10, 2005
Posts: 242
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


Thanks and Regards, Anand
SCJP 5.0 310-055 73%, SCWCD 1.4 310-081 78%, IBM DB2 9 Fundamentals 000-730 62%
anand phulwani
Ranch Hand

Joined: Sep 10, 2005
Posts: 242
Dear Ranchers,

Please Help me out on this question too.

Thanks,
With Regds,
Anand
Karu Raj
Ranch Hand

Joined: Aug 31, 2005
Posts: 479
hey anand

from where did you get this question
Jimmy Thomas
Greenhorn

Joined: Aug 17, 2005
Posts: 19
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.
 
jQuery in Action, 2nd edition
 
subject: Threads,locks problem
 
Similar Threads
synchronized
Synchronization
Thread Doubt
Want help...
Thread synchronize question from JQ+ test