java mkdirs非线程安全

  1. mkdirs:使用注意,仅仅有创建了目录才返回true,即,整个目录存在,也返回false

    Creates the directory named by this abstract pathname, including any necessary but nonexistent parent directories. Note that if this operation fails it may have succeeded in creating some of the necessary parent directories.

    Returns:

    true if and only if the directory was created, along with all necessary parent directories; false otherwise

  2. 非线程安全:线程A创建目录/var/parentDir/dirA,线程B创建目录/var/parentDir/dirB,假定parentDir目录不存在,线程A创建成功,由于递归调用,线程B创建parentDir时失败,由于短路操作,DirB不创建了


ref:

http://cache.baiducontent.com/c?m=9d78d513d99b12eb0bfa940f524f813d591597634dc0a16668a7965fe3664c373671e3ca30521413a4c76b6671b83828fd864265470237c6eadccf0a83b4c86e69ca303503019b114c8e4cb8cb31748076cc4de9d845b0fced71c8f28c888e070f9f4e563ac6abda0457099c38b6476abde7844c165d14b0ef34&p=8f769a47ce8a11a05bea923657428e&newp=93759a46d1c501e646bbc7710f7acf231610db2151d4db133f9d8d1e&user=baidu&fm=sc&query=java+mkdirs+%CA%A7%B0%DC+%B6%E0%CF%DF%B3%CC&qid=&p1=2 

你可能感兴趣的:(java mkdirs非线程安全)