File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes Synchronize keyword Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Synchronize keyword" Watch "Synchronize keyword" New topic
Author

Synchronize keyword

Joel Bijapurkar
Greenhorn

Joined: Aug 01, 2011
Posts: 20

Suppose i synchronize a instance method in a class and create two objects A and B of the same class. Now when object A is accessing the synchronized method will B also be able to access it or will it have to wait until A releases the lock?
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4240
    
    7

They lock different objects (the instance in question), so the methods will be able to run at the same time.

If you synchronized a static method, that locks the class object, and so then any call can block any other.
Joel Bijapurkar
Greenhorn

Joined: Aug 01, 2011
Posts: 20

Thanks Matthew.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Synchronize keyword
 
Similar Threads
Thread lock doubt
synchronized
how can I synchronize a class in java
Synchronized Static Method
How to Synchronize a class??