Posted by digitalsol
on March 8, 2010 at 3:05 AM PST
currently I'm writing a client using LWUIT which is talking with a servlet. I have a HttpWorker class which extends Thread and in there the http connection is initialized along with the Output and Input streams.
I knew that there is problem with the HttpConnection timeout (for me it's not working at all), so I created a TimerTask which tries to close the connections and the streams after some times.
I have 3 general timeouts :
1. The HttpWorker tries to connect, there is no response and the connections throws exception.
2. The HttpWorker is connected, but at some moment the connections breaks (the wireless disconnects), and an exception is thrown.
3. Here comes the problem. If, for example, the servlet stops in the middle for some reason, or if there is no clear indication that the connection is lost, this method :
httpConnection.openInputStream(); blocks my worker thread.
I can't close the connection from other thread, I can't close the io stream (because it's still not assigned, for example InputStream is = httpConnection.openInputStream(), the method blocks before return).
When my TimerTask start, I try to interrupt the other thread, I try to close the connection, but nothing happens. That method just blocks and I can't do anything.
I use LWUIT's Display.invokeAndBlock() https://lwuit.dev.java.net/nonav/javadocs/com/sun/lwuit/Display.html#invokeAndBlock (java.lang.Runnable)
in order to avoid UI freeze, but I don't know how to get around the other problem.
How can I kill the connection ?
There must be some way to get around this, can somebody help me with this ?
Thanks you in advance