I created a web application that works with FLV files.
This application uses the library that I created to analyze content from FLV files. This library uses the FileChannel to search for a file.
Now I am experiencing strange behavior when I search for the same flv file from different streams. Let's say that Thread_1 and Thread_2 are simultaneously looking for movie.flv (my question comes after the example).
Thread_1
// Thread_1 moves to position 200 to read something FileChannel chan1 = new FileInputStream("movie.flv").getFileChannel(); chan1.position(200);
Thread_2 (executed immediately after Thread_1 )
// Thread_2 moves to position 600 to read something else FileChannel chan2 = new FileInputStream("movie.flv").getFileChannel(); chan2.position(600);
Finally Thread_1 does:
ByteBuffer bb = ByteBuffer.allocate(40); chan1.read(bb);
Is Thread_1 reading 40 bytes from position 200 or from position 600? More precisely, are chan1 and chan2 independent (= can search independently) for channels or not?
I read from the documentation that FileChannel is unique , so my bet (unfortunately) is that in the example Thread_1 will be read from position 600: \
In the case, can you suggest a different approach for finding a file regardless of different streams?
thanks!
source share