Closed huntc closed 9 years ago
I suggest doing the reading using something like the following: https://gist.github.com/viktorklang/5409467
Actors shouldn't block. This means that you can interrupt currently running async&blocking reads.
Can you successfully interrupt a blocking IO read? Where is that documented? Thanks.
http://docs.oracle.com/javase/7/docs/api/java/io/InputStream.html#read(byte[])
Now that is an excellent question @huntc, I thought that was appropriately documented on InputStream, but of course it cannot make such guarantees itself, (see: http://docs.oracle.com/javase/7/docs/api/java/io/InputStream.html#read()), and surprisingly it isn't even mentioned in http://docs.oracle.com/javase/7/docs/api/java/io/FileInputStream.html#read(),
Having jumped into the rabbit hole, I have now found myself in a 14 year old bug report: http://bugs.java.com/bugdatabase/view_bug.do?bug_id=4514257
So, it does seem like interrupting is not possible, however, one may be able to call close()
on the InputStream: https://stackoverflow.com/questions/3843363/thread-interrupt-not-ending-blocking-call-on-input-stream-read
Thought of that too. :-) Unfortunately, the close
method on an InputStream
makes no guarantees of thread safety; thus it should not be called on a separate thread to read
.
@huntc It's better to call and wrap in a try-catch than to let Threads hang, I suppose?
Still no guarantees though...
@huntc There are no guarantees that the hardware will work either.
FileChannel implements InterruptibleChannel: http://docs.oracle.com/javase/7/docs/api/java/nio/channels/FileChannel.html
Hmm ... FileChannel
looks useless here. Maybe implement AbstractInterruptibleChannel
.
…ProviderFactoryBeanServiceVisitor
InputStreamPublisher
blocks its actor thread when reading from a stream. This causes a problem when the actor system is shutdown as the publisher will never receive its stop message.The following JVM dump illustrates the thread being blocked. The dump was taken once
system.shutdown()
and thensystem.awaitTermination()
had been called.