File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Java 8 in Action this week 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 ]
It is sorta covered in the JavaRanch Style Guide.
subject: how thread can aquire more than one lock
Similar Threads
Entangled in Threads
Please explain
Doubt in one question
Threads: Doubt
Doubt In Thread Topic