加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 为什么在Guava中弃用Files.deleteDirectoryContents()?

发布时间:2020-12-14 05:29:36 所属栏目:Java 来源:网络整理
导读:在Guava 10中,Google已经弃用了 Files.deleteDirectoryContents().JavaDoc说 Deprecated. This method suffers from poor symlink detection and race conditions. This functionality can be supported suitably only by shelling out to an operating syst
在Guava 10中,Google已经弃用了 Files.deleteDirectoryContents().JavaDoc说

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讨论组.你甚至可以在讨论组上礼貌地问道,但如果你的议程是改变主意,我怀疑你会成功.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读