Java文件锁使用两个不同的流,相同的线程

时间:2016-12-15 06:18:46

标签: java multithreading

FileOutputStream fileOutputStream = new FileOutputStream(myFile);
FileChannel channel = fileOutputStream.getChannel();
FileLock lock = channel.tryLock(); // specifically not using lock, 
FileInputStream fileInputStream = new FileInputStream(myFile);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(fileInputStream));
 while ((line = bufferedReader.readLine()) != null) {}

java.nio.channels.OverlappingFileLockException

的结果

我认为这会起作用,因为两个流都在同一个线程/进程中。但是锁似乎是基于流应用的?

0 个答案:

没有答案