views:

555

answers:

2

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:

  • First request (after initialization) = 20sec
  • Repeating the first request = 5sec

Without making request in initialization:

  • First request = 40sec
  • Repeating the first request = 5sec
+2  A: 

...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.

KarlP
if that´s the case, would it work to make a request to 127.0.0.1?
Decio Lira
what is the net stack? how to initialize this without making a request?
Daniel Moura
What I meant was everything that needs to be working in order to send your bits to the reciever.
KarlP
+3  A: 

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

The application will use an apn that only access one specific address. Can the application try to make a connection to another address to leave the connection open?
Daniel Moura
The behaviour will really depend on the IP-stack implementation of the handset. So you could find all kinds of wonderful quirks of the handset.I would say though, that if you try to connect to another address which is denied by the APN, it is a fair assumption that the connection will close. As you have control over the APN can you open up anther "test" address? Or make a connection to the single available address?