Not right out of the box, no. Normally, Reader aborts the read () call only when another thread closes the main thread, or you reach the end of the input.
Since read () is not so interruptible, this becomes a parallel programming problem. A thread that knows about the timeout should be able to interrupt a thread that is trying to read input.
In fact, the read stream will have to query the Reader ready () method, and not be blocked in read () when there is nothing to read. If you put this polling and waiting operation in java.util.concurrent.Future, then call the get () method of Future with a timeout.
This article is detailed: http://www.javaspecialists.eu/archive/Issue153.html
source share