aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Entangled in Threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Entangled in Threads" Watch "Entangled in Threads" New topic
Author

Entangled in Threads

Umamaheswaran BS
Greenhorn

Joined: Jul 03, 2006
Posts: 4
In locking and synchronisation, We have the following text from K&B
:
"a thread can enter
a synchronized method, thus acquiring a lock, and then immediately invoke a
synchronized method on a different object, thus acquiring that lock as well...."
Now with a code please explain me clearly what is the object that is being talked about here...
Karol Kisielewski
Greenhorn

Joined: Jun 28, 2006
Posts: 8
Originally posted by Umamaheswaran BS:
In locking and synchronisation, We have the following text from K&B
:
"a thread can enter
a synchronized method, thus acquiring a lock, and then immediately invoke a
synchronized method on a different object, thus acquiring that lock as well...."
Now with a code please explain me clearly what is the object that is being talked about here...


class A {
public synchronized void foo() {}
}

class B {
private A a = new A();

public synchronized void bar() {
a.foo();
}

public static void main(String[] args) {
B b = new B();
b.bar();
}
}
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

"Umamaheswaran BS,"

Welcome to JavaRanch!

Please revise your display name to meet the JavaRanch Naming Policy. To maintain the friendly atmosphere here at the ranch, we like folks to use real (or at least real-looking) names, with a first and a last name. Initials are okay for the first, but not the last.

You can edit your display name here.

Thank you for your prompt attention, and enjoy the ranch!

-Marc


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
 
Consider Paul's rocket mass heater.
 
subject: Entangled in Threads