how do I interupt a blocking InputStream?

I need to interrupt an InputStream blocked on the read() call. this stream is not necessarily a socket, so soTimeout will not work here.I have tried interrupt on the thread, but it does not work. any ideas?
[227 byte] By [dnoyeB] at [2007-9-26 3:25:31]
# 1

> I need to interrupt an InputStream blocked on the

> read() call. this stream is not necessarily a socket,

> so soTimeout will not work here.

>

> I have tried interrupt on the thread, but it does not

> work. any ideas?

By only doing the read if a character is available.

while(in.available())

{

... in.read ( ... ) ;

}

MartinS. at 2007-6-29 11:46:27 > top of Java-index,Archived Forums,Java Programming...
# 2
Never mind, I found it. Just close the socket/file/process...
dnoyeB at 2007-6-29 11:46:27 > top of Java-index,Archived Forums,Java Programming...
# 3

> I need to interrupt an InputStream blocked on the

> read() call. this stream is not necessarily a socket,

> so soTimeout will not work here.

>

> I have tried interrupt on the thread, but it does not

> work. any ideas?

By only doing the read if a character is available.

while(in.available()){ ... in.read ( ... ) ;}

MartinS. at 2007-6-29 11:46:27 > top of Java-index,Archived Forums,Java Programming...
# 4

> > I need to interrupt an InputStream blocked on the

> > read() call. this stream is not necessarily a

> socket,

> > so soTimeout will not work here.

> >

> > I have tried interrupt on the thread, but it does

> not

> > work. any ideas?

>

> By only doing the read if a character is available.

>

> while(in.available()){ ... in.read ( ... )

> ;}

This is an infinitely more robust solution than the technique I was using. It has eliminated lots of code and 1 thread from my program.

I guess you have to look closer and be sure to make good use of the threads that are already present before you make new ones.

Thank you!!

dnoyeB at 2007-6-29 11:46:27 > top of Java-index,Archived Forums,Java Programming...