Deprecated. This method suffers from poor symlink detection and race
conditions. This functionality can be supported suitably only by
shelling out to an operating system command such as rm -rf or del /s.
This method is scheduled to be removed from Guava in Guava release
11.0
我为什么会有一个竞争条件感到困惑.我认为使用这种方法实际上是有用的,并且发现操作系统的一个糟糕的解决方案.作者可以分享为什么做出这个决定吗?
解决方法
I am confused on why there is a race condition.
例如,假设一个线程调用Files.deleteDirectoryContents()并且第二个线程(或外部进程)同时在目录中创建一个新文件.
当您从通话中返回时,您可以依靠目录为空吗?不!
无论如何,如果你发现这个方法的功能是有用的…尽管它的缺陷…你可以自由地获取代码的副本,调整它,并将其嵌入到你的应用程序. (只需检查Guava源代码许可证,并确保符合它).
Can the authors share why the made this decision?
我认为他们已经有了看到弃用通知.如果您想要更多,请尝试搜索问题跟踪器和Guava讨论组.你甚至可以在讨论组上礼貌地问道,但如果你的议程是改变主意,我怀疑你会成功.