• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Junilu Lacar
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst
  • Peter Rooke
  • Mikalai Zaikin
Bartenders:
  • Himai Minh

Http connections using background threads

 
Ranch Hand
Posts: 341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
author
Posts: 1436
6
Python TypeScript Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A. The worker thread should update the view. Or, it must implement a Observer/Listener pair to notify the main thread.
B. I do not understand the question. Both thread hold references to the value objects. They are inside the same JVM. I do not understand why you need sync.
C. Make sure that you close all connects after you use them. The slow start up time might be caused by setting up the classes and connection infrastructure inside the JVM. I am not sure. It sounds odd through.
D. You must do network and other blocking methods in a separate thread. You might get away by doing it in the main thread for MIDP 1 devices. But for MIDP 2 devices, it will often causes lock-up since another UI thread is used for permission management.
 
When I was younger I felt like a man trapped inside a woman’s body. Then I was born. My twin is a tiny ad:
Master Gardener Program
https://coderanch.com/t/771761/Master-Gardener-Program
reply
    Bookmark Topic Watch Topic
  • New Topic