×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    12

    Threading or Connection Error

    I have a midlet that holds a thread that opens every 10 sec an http connection (in order to keep session alive).

    In the destroyApp() I close the conn in the thread but it happens that when I press the Exit button (The red button),
    The application is marked as disabled and all I can do is erase it.
    and I need to download it again to the phone.

    I think the problem is that the thread holds an open connection or in the middle of data transfer and it doesn't close in the destroyApp()


    What to do????
    Any idea?

  2. #2
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280
    Are you stopping the thread?
    I imagine that the run method would look along the lines of:
    Code:
    public void run() {
      while (isRunning) {
        // perform http connection
        // sleep for 10 seconds
      }
    }
    Are you setting the isRunning variable (your version of it) to false?

    shmoove

  3. #3
    Registered User
    Join Date
    May 2004
    Posts
    12
    Yes.
    The stop function of the thread looks:

    public void stop()
    {
    _allowed = false; //this is the flag
    _timer.cancel();
    closeConnection();
    }

    but the flag will influence the next tick,
    I afraid that the thread already in a previous loop in the middle of a data transfer. and the close function cause some trouble or has no affect at all.

  4. #4
    Registered User
    Join Date
    Apr 2003
    Posts
    10
    Hi,
    I don't know your code but it seems strange to open every 10sec. a Httpconnection justo to keep a session.
    I'm having application like this that has a thread that does the http requests and i don't have such problems. Did you look at the examples that Nokia provides. To be more specific Sum midlet and Sum servlet. There is an example how to keep a session.

    Best regards,
    Emil

  5. #5
    Registered User
    Join Date
    May 2004
    Posts
    7
    Hi,

    Could you try to synchronize the two parts using the connection?

    BR.

    JD_J2ME

  6. #6
    Registered User
    Join Date
    May 2004
    Posts
    12
    What do u mean exactly by saying synchronize?

  7. #7
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280
    What phone are you testing on?

    From your description, if you are really closing the thread, then the worst case scenario is that the thread has already initiated the connection. In this case what should be happening is that the connection should just go through all it's necessary stages, get ignored, and then the MIDlet could be activated again.

    There could be two issues I can think about:
    1) You are using a Series 60 device and closing the MIDlet with the red "End" button. This button doesn't really close the MIDlet, it only moves it to the background and I don't think destroyApp() is called.
    2) The initiated connection is getting stuck, so the program can't end properly. In this case there is probably something wrong with the phone's connection settings.

    shmoove

  8. #8
    Registered User
    Join Date
    May 2004
    Posts
    7
    If a prgram tries to close a connection that is in reading or writing state from another thread, it may cause a problem even in J2SE implementation because the code may try to read or write to or from a connection that is or is being closed especially when exiting an application. Therefore we need to synchronize the closing connectin part and the reading and writing part. The code should avoid reading or writing to or from a connection that is or is being closed.

    You said "a midlet that holds a thread that opens every 10 sec an http connection (in order to keep session alive)." Does your thread or the server close the previous connection before you open a new one? Do you have multiple alive http connections symatanously?

    Do you have to always open new http connections repeatly to keep a session alive?

    Have you tested your code on Nokia simulators? Is the thread closed correctly and it there any exception?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×