多个 RandomAccessFile 对象可以将数据写入同一个文件吗?

Can multiple RandomAccessFile objects write data to same file?

 public class WriteThread extends Thread{

        @Override
        public void run() {
            RandomAccessFile randomAccessFile = new RandomAccessFile(fileName, "rwd");
            randomAccessFile.seek(threadPosition);
            byte[] buffer = new byte[1024 * 8];
            randomAccessFile.write(buffer, 0, threadLength);
        }
    }

在我的代码中,每个线程通过各自的RandomAccessFile object.Does 将数据写入同一个文件需要同步?抱歉我的英语不好。

Can multiple RandomAccessFile objects write data to same file?

是的,我们在 Chronicle 的图书馆中这样做。

In my code, each thread writes data to the same file through respective RandomAccessFile object.Does that need to be synchronized?

你还需要担心线程安全问题。 synchronizedLock 将起作用,但是,这不适用于 JVM。如果您有多个 JVM,则需要使用低级别堆外线程安全操作的共享锁。 (这是我们所做的,因为它是最快的选择)