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 Static method Synchronization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Static method Synchronization" Watch "Static method Synchronization" New topic
Author

Static method Synchronization

sr shashidhar
Greenhorn

Joined: Jan 17, 2013
Posts: 27
Hi frndz,

Consider we have DEMO class in which two methods(Both are Static Synchronized) say method1() and method2().
Two user defined Threads AThread extends Thread class and BThread implements Runnable interface is running in the program.

1) Suppose if Athread is calling method1() with object a1(DEMO a1=new DEMO();) and Bthread is also calling method2() with same object a1. What will be the flow of execution? i mean its either Concurrent or Sequential...?

2) Suppose if Athread is calling method1() with class name DEMO and Bthread is also calling method2() with class name DEMO. What will be the flow of execution? i mean its either Concurrent or Sequential...?


thanks in advance
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1505
    
    5

Hi,

When you say something like:



it simply means



So, since lock is acquired over 'class', and this is only one per class, only one thread can execute the method - no matter which object is being used to invoke this method.

Thus, answer to your question - the execution will be sequential in both scenarios.

HIH.


Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
sr shashidhar
Greenhorn

Joined: Jan 17, 2013
Posts: 27

Thanks Anayonkar Shivalkar.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Static method Synchronization