开发者

What concurrency works with the java file system?

Using java IO, it seems like forking a new process gives better ability for a process B to read data written by process A to file than what you could开发者_如何学C get if thread A wrote to a file that thread B is trying to read (within the same process).

It seems like the rules are not comparable to the memory model. So what file-based concurrency works ? References would be appreciated.


Any observations like this bound to be operating system specific, and may be specific to different versions of the operating system (kernel). What you are hitting here is probably related to the way that the OS implements threads, and thread scheduling. The Java platform provides little in the way of tuning for this kind of thing.

IMO, if you need better performance, you probably should not be using a file as a data transfer channel between two threads in the same JVM. Code your application to detect that the threads are colocated in the same JVM and use (say) Java Pipe streams.


Maybe it could have to do with thread and process blocking.

When a process wants a resource (writing/reading a file) it blocks untils the S.O. fulfills the requirement and return something to the process.

If you are not using hyperthreading a process with two threads will block both threads for fullfilling each one of the tasks. But if you separate them, maybe the S.O. can optimize access and paralelize the read/write better.

(just guessing :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜