I have a SwingWorker
which is supposed to execute 3 methods sequentially one after another. The method 1 contains a while loop for a BufferedReader
. This while loop never terminates as the BufferedReader
is never signalled with an end. I want to terminate the loop using some kind of a timer after 5 seconds. How do I do this?
public class TestWorker extends SwingWorker<Void,Void>{
public TestWorker(){
}
private void doSomething1(){
TelnetClient telnetClient
telnetClient = new TelnetClient();
telnetClient.connect(telnet_IPAddress, telnet_Port);
InputStream telnetInputStream = telnetClient.getInputStream();
try (BufferedReader br = new BufferedReader(new InputStreamReader(telnetInputStream))) {
String line;
while ((line = br.readLine()) != null) {
//Do something
//The bufferedreader is not signaled with an end of a stream. I want to terminate this loop after 5 seconds.
}
} catch (IOException ex) {
}
}
private void doSomething2(){
}
private void doSomething3(){
}
@Override
public Void doInBackground() {
doSomething1();
doSomething2();
doSomething3();
return null;
}
@Override
public void done() {
//Update something on a GUI
}
}