This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Threads: Doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Threads: Doubt" Watch "Threads: Doubt" New topic

Threads: Doubt

dedcat achi

Joined: Jun 22, 2008
Posts: 11
Can someone please explain this:

"A thread can acquire more than one lock. For example, 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. Also, if a thread acquires a lock and then attempts to call a synchronized method on the same object, no problem."

Can you please give an example this to explain the above statements.

Deepak Bala

Joined: Feb 24, 2006
Posts: 6661

Here is an example

The lock of this object, System.out is obtained. Another synchronized method is called from the body of the synchronized block

SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
dedcat achi

Joined: Jun 22, 2008
Posts: 11
I agree. Here's the link:
subject: Threads: Doubt
Similar Threads
Doubt In Thread Topic
how thread can aquire more than one lock
Entangled in Threads
static synchronized
Please explain