Killing thread that is doing blocking WRITE.
Hello,
I got a problem with threads: I have to write something (currently using FileWriter) to a device (file) which is not always available for writing - the write()/flush() function is being blocked in such case. I also have to implement timeout - if write()/flush() aren't able to accomplish writing in the given period of time, the write should be aborted.
My solution is to create new thread responsible for writing and wait with join(timeout) or notify()/wait(timeout) until it finishes. But what should I do when the thread didn't succeed (write()/flush() is still blocked)?
I have to finish the thread somehow. But I can't use stop() neither interrupt() (deprecated/not working while blocking IO is in progress).
The method with closing stream doesn't work, because close() calls flush() - which blocks the parent thread either. I guess it only works for reading, not for writing (well, maybe if the buffer was empty - but that's not my case). Maybe there is a way to close() an OutputStream without flushing its contents?
Any ideas?
Thanks,
Robert

