This week's book giveaways are in the iOS and Features new in Java 8 forums.
We're giving away four copies each of Barcodes with iOS: Bringing together the digital and physical worlds and Core Java for the Impatient and have the authors on-line!
See this thread and this one for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes how thread can aquire more than one lock Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Barcodes with iOS this week in the iOS forum
or Core Java for the Impatient in the Java 8 forum!

JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "how thread can aquire more than one lock " Watch "how thread can aquire more than one lock " New topic

how thread can aquire more than one lock

Shashank Sharma
Ranch Hand

Joined: Sep 27, 2006
Posts: 91
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.

Above lines are taken from K& B page no708.

here author is talking about simultaneously obtaining a lock on " different object ",how do we re declare the same thread with a new runnable object.

please help me with this .please provide an example if any one can
thanks in advance
Ireneusz Kordal
Ranch Hand

Joined: Jun 21, 2008
Posts: 423
How obtain many locks:

How declare thread using Runnable:

Someone uses method with anonymous class that implements Runnable
- remember: Runnable is an interface, not a class!!!

And this also starts the Thread:

[ August 06, 2008: Message edited by: Ireneusz Kordal ]
I agree. Here's the link:
subject: how thread can aquire more than one lock