Hi !
My midlet sends some data to a
servlet using Httpconnection. Then it recieves a response from the server and shows a message based on that response.
Following is how I do it:
1) Main
thread displays the Busy/Progress screen
2) A child thread is created that carries out network communication. It receives a response from the server and then displays new screens.
My questions are:
A) Should the child thread that does the networking, display GUI's. Or it should only do network communication.
I can't change the GUIs in the main thread so I have to change them in the networking thread.
B) What about synchronization issues. Suppose I have a Form object in my main thread. Then it would be updated in the child thread. So do I need to serialize access to such code. BTW, i read somewhere that the MIDP user interface classes are thread-safe. I don't really understand what does it mean.
C) When I press the "Send" button for the first time it takes around 20 seconds for the "Confirmation" screen to appear. In other words the Busy/Waiting screen stays for around 20 seconds. But if I use this feature again (without exiting or closing the emulator)I get the confirmation screen in less than 3 seconds. Why is this so ? Maybe the networking thread is still running and network connections have not been closed. This is why it takes less time if I use the app from the second time. But it takes lot of time when I use it for the first time.
D) If I do all the work (network communication, etc...) in main thread, I get the confirmation screen in less that 5 seconds. But I can't have a Busy screen. On the other hand if I use child thread for networking and get a progress screen in main thread then it takes around 20 seconds for the confirmation screen to appear. Since response time is critical so using the main thread do all work seems a better approach (ofcourse i won't get the Busy screen). ANy comments ?
Regards
Danish
[ July 26, 2003: Message edited by: Danish Shaukat ]
[ July 26, 2003: Message edited by: Danish Shaukat ]