Only one thread is creating. Under certain circumstances it needs to be shut down.
In this case it can be done by checking isInterrupted(). But it freezes on in.readUTF() if there is empty InputStream. How this can be fixed?
DataInputStream in;
....
public void stop() {
thread.interrupt();
}
public void run() {
while(true) {
String str = in.readUTF(); // locking here, when stream is empty
S.o.p(str)
if(isInterrupted) {
return;
}}
}
public void main(String args[]) {
Thread thread = new Thread();
}
You cannot interrupt a blocked InputStream. (This is one of the differences with NIO) You can instead close the stream before calling interrupt and this will trigger an IOException.