使用多线程写入单个文件
我可以使用多线程在Java中的RandomAccessFile中写入吗?
我知道 RandomAccessFiles 允许读取和读取在任意位置写入。
我想创建上面文件的n部分并让每个线程写入 特定部分的内容。
它会提高 IO 性能吗?
渴望尽快听到......
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?
Eager to hear soon......
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用指定的正确共享打开该文件两次,使两个 RandomAccessFile 对象指向同一文件。如果您小心不要对同一位置写入和读取两次,操作系统将正确管理(操作系统也会处理它,但您会得到意想不到的结果)。
然而,它不会提高您的 I/O 性能 - CPU 几乎从来都不是 I/O 的瓶颈。你想达到什么目的?
You can open the file twice with the proper sharing specified, having two RandomAccessFile objects pointing to the same file. The OS will manage properly if you're careful not to write and read the same location twice (the OS will handle it then, too, but you'll get unexpected results).
However, it will not improve your I/O performance - CPU is almost never the bottleneck when it comes to I/O. What is it you're trying to achieve?