Skip to main content

HttpConnection timeout, freeze, thread issues

1 reply [Last post]
digitalsol
Offline
Joined: 2009-10-11
Points: 0

Hello everybody,

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

Best regards

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
digitalsol
Offline
Joined: 2009-10-11
Points: 0

Please check this out :
[b]I have heard about this problem before - on quite a few Nokia phones this is a bug en the MIDP-implementation in the phone-software, which means you cannot solve the problem - when dealing with connections in MIDP, phones from Nokia have several bugs, e.g:

Beneath the HttpConnection a StreamConnection-instance is used. On Nokia Phones using the MIDP-specification, the StreamConnection has a serious bug. The only way to break out of StreamConnection.read() is when data is received. If you call StreamConnection.read() when no data is waiting in the in-buffer, the method blocks until data is received with no chance to interrupt. "That's why you have the StreamConnection.available()-method to tell me how much data the in-buffer contains", but wrong, available() always returns 0, no matter how many data the buffer contains. Also you cannot write to a StreamConnection, when blocked in read().

The bugs mentioned above ahev been seen for other than Nokia phones too, and could be the reason of your problems. Maybe a firmware-update for your mobile phone might help. Which mobile phone are you using?

If a firmware-update does not work, you will have to work yourself around the problem, e.g. by "telling" the server to close the connection...[/b]
from here http://www.experts-exchange.com/Programming/Languages/Java/Q_21103094.html

My phone is E71, maybe this is causing the problem ?