Cannot use setReadTimeout(), any other alternative ?
Hi,
i have a very typical problem. I am trying to get an inputstream by using conn.getinputstream(), and of course as everybody knows, the program hangs if the inputstream doesn't come or is delayed.
I cannot use setReadTimeout() because i have a limitation of working with Java 1.4.2.
I tried creating another timer thread. But was not able to influence the getInputStream in any way. Neither have i been able to throw an exception from my timer thread to my main thread where i can catch and take appropriate action. I created a getInputStreamTimeout() method as a part of the Timer class which encapsulates the getInputStream() call.
code looks smthing like this :-
class TimerThread extends Thread {
void run(); //usual implementation of a timer.
timeout(); //method fired when elapsed time > max length
InputStream getInputStreamTimeout(URL Connection conn, TimerThread tt) {
try{
tt.start(); // starts the timer thread
tempIS = conn.getInputStream();
return tempIS;
} catch { ...}
}
}
i even tried a divide by zero operation in timeout() , it doesn't gets caught in getInputInputStreamTimeout()
The the callin snippet in Main program looks like
try{
TimerThread tt = new TimerThread(10000); //constructor which takes in MAX time
TempInpStream = tt.getInputStreamTimeout(conn, tt);
return TempInpStream;
} catch { ... }
Please help me guys, im new to java :-) !!

