Reputation: 7956
I'm maintaining a J2ME application where I found a http request to http://www.google.com in application initialization. I asked the developer why there is a request to google. He said that this way the other requests that the application makes would be faster.
I removed this request to google.com and the other requests got slower.
Can anyone explain why this happened? How can I make the other request faster without making previous requests?
EDIT:
Making request to google in initialization:
Without making request in initialization:
Upvotes: 3
Views: 1668
Reputation:
On a mobile device initiating the web connection will take sometime and quite often the JVM will leave the connection open for the duration of the MIDlet running (most modern connections are charged per byte - Edge, GPRS, WiFi). So if a connection is made on startApp, you might find the connection will stay open and all further communication will not need to open a connection, only send data. So fast and more reliable!
This behaviour is platform specific, MIDP2 does not stipulate this to be true (so Nokias may differ to Samsungs etc).
Connecting to 127.0.0.1 will probably not fool the JVM, which may decide it doesn't need an open GPRS connection for that. Again platform specific.
James
Upvotes: 4
Reputation: 5201
...maybe the first request initializes the network layer(*) in the device and maybe also the jvm.
I am sure it works with www.microsoft.com too :-)
*) I suspect this depends on what device you are running on. I have no idea whats going on, but there might be anything. For example : Starting the radio device, setting up a session with the network operator, loading and starting classes in the jvm.
Try to connect to 127.0.0.1 instead of google and see if that makes later attempts quicker.
If the application is doing a lot of initalizations that takes a while before doing the first real connection attempt, you can start a new thread early that does a connection attempt. Maybe that will reduce the total waiting time.
Upvotes: 2