I have a multi-threaded program, in which I open a BufferedReader
to read content from FIFO(named Pipe)
file. As I want to implement stream type of solution to read text from FIFO file continuously, I have created a BufferedReader outside of thread task run, and want to keep that open forever as long as application is running.(No close() on bufferedReader)
With the limited(let say 10) threads in ThreadPool will keep look for text in FIFO file and process that text for further. As I am using FIFO it will never reach END OF FILE.
By doing this, For a smaller input file it reads successfully, for a large input file it throws Stream closed IOexception
(sporadically). It close automatically, I do not have close()
statement.
I have a code in place to acquire and close the semaphore lock
at the place where i use br.readLine()
to handle race condition issue
java.io.IOException: Stream closed
at java.io.BufferedReader.ensureOpen(BufferedReader.java:122) ~[?:1.8.0_152]
at java.io.BufferedReader.readLine(BufferedReader.java:317) ~[?:1.8.0_152]
at java.io.BufferedReader.readLine(BufferedReader.java:389) ~[?:1.8.0_152]
Question:
- For this solution I do not want to close the BufferedReader. What are the consequences?
- Can I have a bufferedReader which never be closed? if so what steps I should consider in code.