How to use mkdirs in a thread safe manner in Java?

前端 未结 5 2277
执念已碎
执念已碎 2021-02-14 17:51

After experiencing issues with mkdirs() and poking around the interwebs, I get the impression that there are thread safety issues with mkdirs().

Is there a way to ensure

5条回答
  •  暖寄归人
    2021-02-14 18:49

    Eaven if this thread is a bit older I wonder if there is somethink wrong with the following solution:

    package service;
    
    import java.io.File;
    
    public class FileService {
    
        public static synchronized boolean mkdirs( File dir ) {
            return dir.mkdirs();
        }
    }
    

提交回复
热议问题