File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Threads: Doubt" Watch "Threads: Doubt" New topic
Author

Threads: Doubt

dedcat achi
Greenhorn

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.

Thanks!
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

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
Greenhorn

Joined: Jun 22, 2008
Posts: 11
Great!
Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Threads: Doubt