Commits

Anonymous committed 8a96312

CACHE-322 File.mkdirs isn't thread safe (Sun Bug ID 4742723)

Comments (0)

Files changed (1)

src/java/com/opensymphony/oscache/plugins/diskpersistence/AbstractDiskPersistenceListener.java

  */
 public abstract class AbstractDiskPersistenceListener implements PersistenceListener, Serializable {
 	
+    private static final long serialVersionUID = 6679402628276452293L;
+
     private static final Log LOG = LogFactory.getLog(AbstractDiskPersistenceListener.class);
 
+    /** lock for workaround the Sun Bug ID 4742723 */ 
+    private static final Object MKDIRS_LOCK = new Object();
+
     public final static String CACHE_PATH_KEY = "cache.path";
 
     /**
                         log.info("cache.path '" + cachePathStr + "' does not exist, creating");
                     }
 
-                    cachePath.mkdirs();
+                    // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4742723
+                    synchronized (MKDIRS_LOCK) {
+                        cachePath.mkdirs();
+                    }
                 }
 
                 if (!cachePath.isDirectory()) {
 
             try {
                 if (!filepath.exists()) {
-                    filepath.mkdirs();
+                    // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4742723
+                    synchronized (MKDIRS_LOCK) {
+                        filepath.mkdirs();
+                    }
                 }
             } catch (Exception e) {
                 throw new CachePersistenceException("Unable to create the directory " + filepath, e);