Will using multiple threads with a RandomAccessFile help performance?

后端 未结 7 2099
滥情空心
滥情空心 2020-12-03 16:32

I am working on a (database-ish) project, where data is stored in a flat file. For reading/writing I\'m using the RandomAccessFile class. Will I gain anything f

相关标签:
7条回答
  • 2020-12-03 16:50

    Looking at the JavaDoc on RandomAccessFile the class itself is not synchronized. It appears that you can use a synchronous mode for read and write operations. If you don't use the synchronized mode though you are going to have to manage the locks on reading and writing yourself which is far from trivial. The same is going to be true for straight java.io when using multiple threads.

    If at all possible you probably want to look at using a database since a database provides this kind of multi-threaded abstraction. You might also look at what syslog options are available for Java or even log4j.

    0 讨论(0)
提交回复
热议问题