This could also be written “Synchronize on the Class instance”, which means the lock is obtained on the result of MyClassname.class.  In this way, synchronized static methods can be used to control access by all threads to a single shared object (ie. to an object declared 'static' or to a singleton of some kind).  In such cases the synchronized keyword can be put on the method signature of the static method. eg.

public class RuleManager
{
    public static synchronized applyRulesToFileSystem(RuleManager manager)
    {
        :

In the above case, the lock is on the RuleManager.class instance, so no two callers from any thread can call applyRulesToFileSystem( ) at the same time – rightly so since it modifies the file system.

blog comments powered by Disqus