This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread 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 Building Microservices this week in the Design 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 ]
Have you checked out Aspose?
subject: how thread can aquire more than one lock
It's not a secret anymore!