[英]Java library like org.apache.commons.io.FileUtils but contains instance methods instead of static methods
I was wondering what is the point of only having static methods in FileUtils? 我想知道在FileUtils中仅使用静态方法有什么意义? Is there a reason not to have instance methods? 是否有没有实例方法的理由? I believe FileUtils is thread-safe (Correct me if I am wrong lol), but I do have a bunch of threads using the FileUtils methods at the same time, and it seems like having multiple instances would work better than having synchronized code. 我相信FileUtils是线程安全的(如果我错了,请纠正我,大声笑),但是我确实有很多线程同时使用FileUtils方法,而且似乎有多个实例比同步代码更好。 Is there a library that mimics the FileUtils library, but does not contain any static methods? 是否有一个模仿FileUtils库但不包含任何静态方法的库?
I was wondering what is the point of only having static methods in FileUtils? 我想知道在FileUtils中仅使用静态方法有什么意义? Is there a reason not to have instance methods? 是否有没有实例方法的理由?
Because FileUtils
is a collection of stateless methods. 因为FileUtils
是无状态方法的集合。 It wouldn't make sense to introduce an object for it - what would it contain? 为此引入一个对象是没有意义的-它包含什么?
I believe FileUtils is thread-safe. 我相信FileUtils是线程安全的。
It all depends on what and how you're trying to achieve sth. 这完全取决于您要达到的目标以及目标。 If you eg try to read from multiple or even the same file in multiple threads it'll work fine. 如果您尝试从多个线程中读取多个甚至同一文件,则可以正常工作。 However if you try eg to write to the same file from within multiple threads you may have some problems. 但是,如果您尝试从多个线程中写入同一文件,则可能会遇到一些问题。 These problems will stem however from the fact that you're using the same file for writing things and thus do not actually make FileUtils
not thread-safe. 但是,这些问题将源于以下事实:您使用同一文件来编写内容,因此实际上并未使FileUtils
线程安全的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.