在Android的并行文件访问文件、Android

2023-09-05 02:04:49 作者:空山梦

我知道很多操作系统进行某种形式的锁定上的文件系统,以prevent不一致的意见。是否有任何保证,Java和/或Android做出的文件访问线程安全?我想知道尽可能多关于这个问题,可能之前我继续前进,写并发code自己。

I know that many OSes perform some sort of locking on the filesystem to prevent inconsistent views. Are there any guarantees that Java and/or Android make about thread-safety of file access? I would like to know as much about this as possible before I go ahead and write the concurrency code myself.

如果我错过了得到的回答类似的问题,请随时关闭该线程。谢谢你。

If I missed a similar question that was answered feel free to close this thread. Thanks.

推荐答案

Android基于Linux之上,因此继承了Linux的文件系统中的语义。除非你明确地锁定文件,多个应用程序和线程可以打开进行读/写访问。除非你真的需要跨进程的文件同步,我会建议使用普通的Java同步原语的仲裁访问该文件。

Android is built on top of Linux, so inherits Linux's filesystem semantics. Unless you explicitly lock a file, multiple applications and threads can open it for read/write access. Unless you actually need cross-process file synchronization, I would suggest using normal Java synchronization primitives for arbitrating access to the file.

 
精彩推荐