Hello there fellow developers and Nokia personnel!
I've discovered an issue that really worries me!
Heres the scenario:
I create 2 new threads.
First thread is a FullCanvas that displays a simple animation indicating the phone is busy working.
Second thread establishes a HTTPConnection and posts/downloads content.
During runtime the animation thread is started followed by the HTTP thread.
The first frame of the animation screen is displayed, but as soon as the HTTP thread establishes its connection, the animation screen frezzes and seems not to be allowed repainting until the HTTP thread has finnished and disconnected.
My question is: How in heaven can the HTTP thread block my animation screen, when both tasks are running in separate threads and thus should NOT interfere with each other NOR the event mechanism that repaints the display.
Is it really so, that it is impossible to maintain and paint upon the display while communicating on the network?
I would like to describe my problem, which is quite similar, in more details:
I used InputStream::read() to get data from the httpconnection'
s inputstream. The method will block if there is no data currently available (due to the delay in network or other reasons). However, the problem is , even though I process the httpconnection in another thread with min_priority, the read() method will block ALL other thread in the VM, including UI which causes the phone hangs!
This happens in 7210/6610. however, in 6310i emulator, that read() method also blocks, but just that thread, not affecting other ones!
It shouldn't happened in that way. I don't think this situation is so difficult to handle for the MIDP implementation. This will greatly limit the functionality of the programs.
This is also happening with me on the 7210 Emulator. (I will try the Series 60 & 6310i emulator later) Does anyone know if this happens on the phone itself?
This is a killer for my application. I am using streaming HTTP with "chunked" output handling. This appears to work fine - I receive chunks of ouput appropriately spaced - over the same HTTP request.
However this means that I have a long lasting SINGLE Http request outstanding. I read this in another thread and when the InputStream read is blocked, the rest of the application is blocked as well. The Http read will be blocked most of the time.
Is it possible to use some sort of read with instant/short timeout. Then perhaps I could loop with a delay and/or yield before trying again
It looks like http I/O really does block all threads (which of course sucks ! ... Nokia ? ).
For those experimenting with long running http connections (pseudo streaming) you also need to be aware that in most real cases you will be running through a WAP gateway which adds a while bunch of intrusive behaviour.
Yes I solved the problem - or at least found out what was causing the phone to Hang. If you attemp to read from an http inputstream when there is no content data available, the phone will freeze. Thus you should always inspect the Content-lenght header and don't attempt to read more bytes than specified.
If no content-lenght header is provided, you should stop reading as soon as you recieve -1. I've tested this with my animation thread, and it runs smooth without freezing.
However I've given up upon the Chunked transfer encoding.. If anyone has a working example, I would be very happy if you would share :-)