是否可能同时从两个或多个不同的进程中读取同一文件?
我想在Java应用程序中做这样的事情:
final File f = new File("read-only-file");
final FileInputStream in = new FileInputStream(f);
int b;
while((b = in.read()) != null) {
//process b
Thread.sleep(10); //several read processes would really happen at the same time
}
没有应用程序会写入该文件,但是多个线程/应用程序需要同时执行上述代码。上述代码是否正常,还是我需要在这种情况下使用任何特殊机制?
此外,解决方案应该是平台无关的,并且必须在类似Linux的系统上工作。