Can i use multiple threads to write in RandomAccessFile in Java ?
I know RandomAccessFiles allows to read & write at any position.
I want to create n portions of above File and let each thread to write contents in a particular portion.
will it improve IO performance?
渴望很快听到……
最佳答案
您可以使用指定的适当共享打开文件两次,让两个 RandomAccessFile 对象指向同一个文件。如果您注意不要对同一位置写入和读取两次,则操作系统将进行正确管理(操作系统随后也会处理它,但您会得到意想不到的结果)。
但是,它不会提高您的 I/O 性能 - 在 I/O 方面,CPU 几乎从来不是瓶颈。你想达到什么目的?
关于java - 使用多线程写入单个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8238668/