I create a quick bridge between two separate programs.
One program writes to a file, and my program reads it at the same time.
It seems that as soon as I call the first read, the record is completely locked.
Why is this happening and what is the workaround?
// Create Named Pipe Runtime.getRuntime.exec("mkfifo /tmp/mypipe") val stream = new FileInputStream("/tmp/mypipe") val in = new BufferedReader(new InputStreamReader(stream)) // File opened for reading. No blocking at this point. while (true) { println(in.readLine()) // File read. Now blocking. }
Update:
This file is actually a named pipe created with mkfifo /tmp/mypipe . I tried using this with a regular File , and it worked just fine - all the data displayed.
I use a named pipe because I do not need IO overhead on disk.
source share