Well, the problem with the simple
InputStream is that it won't
interrupt if the thread gets
blocked by a
reading or
writing operation, even if you explicitly
interrupt the hanging
thread by calling its
interrupt() method.
Then, instead of using a simple
InputStream, maybe, you should use a
FileChannel:
See
java.nio.channels.FileChannel Since
FileChannels implement
InterruptibleChannel, your thread may be interrupted even while it is
blocked by an IO operation like a
read or a
write.
Then, as Stan suggested, you could ask your
main thread to
join your
"IO thread" for a period of time that you consider reasonable, if when the
join operation ends, the
thread doing the IO operation is not yet
terminated,that's to say if...
!theThread.getState()==Thread.State.TEMINATED ...then you can ask the hanging
thread to
interrupt:
theThread.inturrpt() Be sure to handle
ClosedByInterruptException in the
run() method of your
"IO thread" so that you can do some
cleanup when the IO operation is
interrupted.
Does this sound useful?
[ May 31, 2006: Message edited by: Edwin Dalorzo ]