Will using multiple threads with a RandomAccessFile help performance?

后端 未结 7 2131
滥情空心
滥情空心 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:49

    RandomAccessFile is synchronised, so if you share an instance then you'll only have one thread running at one anyway. Oops, RandomAccessFile is not synchronised, and sharing between threads is not entirely safe. You will, as ever, need to be careful when you have multiple thread accessing the same mutable datastructure, particularly when the vagaries of operating systems are involved.

    Small operations of RandomAccessFile are hideously slow.

    For maximum performance, you are probably better off going straight for java.nio, although I would suggest getting something working before getting it to work fast. OTOH, keep performance in mind.

提交回复
热议问题