IE does not call stop() on applet

Discussion in 'Java' started by karambol, Jun 18, 2004.

  1. karambol

    karambol Guest

    Hi,

    There is a situation:
    An applet in start() method creates a socket and two threads to read from
    and write to it.
    When I open the page, let the applet initialize and then close, everything
    is ok.

    The problem comes up, when I quickly click "back" in IE just after the
    applet starts initializing (sometime about when the Java icon is shown and
    the applet is not yet initialised, and its controls are not yet visible).

    The problem is, that IE is not calling stop(), as supposed, so the applet
    keeps initializing, although it's not visible and I'm watching another site
    (due to clicking "back").

    Question:
    How to stop the threads and close the socket, when user quickly clicks
    "back", and applet keeps initializing itself?

    --
    karambol

    P.S. It's my first post here, so don't bite... yet ;)
     
    karambol, Jun 18, 2004
    #1
    1. Advertising

  2. karambol

    Liz Guest

    "karambol" <> wrote in message
    news:...
    > Hi,
    >
    > There is a situation:
    > An applet in start() method creates a socket and two threads to read from
    > and write to it.
    > When I open the page, let the applet initialize and then close, everything
    > is ok.
    >
    > The problem comes up, when I quickly click "back" in IE just after the
    > applet starts initializing (sometime about when the Java icon is shown and
    > the applet is not yet initialised, and its controls are not yet visible).
    >
    > The problem is, that IE is not calling stop(), as supposed, so the applet
    > keeps initializing, although it's not visible and I'm watching another

    site
    > (due to clicking "back").
    >
    > Question:
    > How to stop the threads and close the socket, when user quickly clicks
    > "back", and applet keeps initializing itself?
    >
    > --
    > karambol
    >
    > P.S. It's my first post here, so don't bite... yet ;)


    It is my understanding that stop() is called when the applet completely
    leaves the screen.
     
    Liz, Jun 18, 2004
    #2
    1. Advertising

  3. karambol

    karambol Guest


    > It is my understanding that stop() is called when the applet completely
    > leaves the screen.



    Well, it does. If I click "back" after, say, 3 seconds or later, everything
    works ok. But if I click "back" "too soon" (meaning: when the start() method
    has not finished yet) the stop() is not called.

    Seems like IE only calls stop() when the start() is over, but I think there
    is something else. I tried creating a thread todo initialisation, so the
    start() method looks like this:

    InitThread it = new InitThread();
    it.start();

    so, how long can that execute?! All initialisation is done in another thread
    now, and stop() is still not called if I exit the page too quickly.

    One more thing: stop() is called when i exit the browser. This is
    understandable, but why not when i leave the page (too quickly)?

    --
    karambol
     
    karambol, Jun 18, 2004
    #3
  4. karambol

    Liz Guest

    "karambol" <> wrote in message
    news:40d29604$...
    >
    > > It is my understanding that stop() is called when the applet completely
    > > leaves the screen.

    >
    >
    > Well, it does. If I click "back" after, say, 3 seconds or later,

    everything
    > works ok. But if I click "back" "too soon" (meaning: when the start()

    method
    > has not finished yet) the stop() is not called.
    >
    > Seems like IE only calls stop() when the start() is over, but I think

    there
    > is something else. I tried creating a thread todo initialisation, so the
    > start() method looks like this:
    >
    > InitThread it = new InitThread();
    > it.start();
    >
    > so, how long can that execute?! All initialisation is done in another

    thread
    > now, and stop() is still not called if I exit the page too quickly.
    >
    > One more thing: stop() is called when i exit the browser. This is
    > understandable, but why not when i leave the page (too quickly)?


    Have you read the documentation? From the tutorial:
    ---
    Does the applet stop running when it's offscreen?

    Most applets should not use CPU resources when the browser is iconified or
    is displaying a page that doesn't contain the applet. If your applet code
    doesn't launch any threads explicitly, then you're OK.
    If your applet code launches any threads, then unless you have a really
    good excuse not to, you should implement the stop method so that it stops
    and destroys (by setting to null) the threads you launched.
     
    Liz, Jun 18, 2004
    #4
  5. karambol

    Roedy Green Guest

    On Fri, 18 Jun 2004 09:13:34 +0200, karambol <>
    wrote or quoted :

    >so, how long can that execute?! All initialisation is done in another thread
    >now, and stop() is still not called if I exit the page too quickly.


    I find it highly unlikely the browser would abort any of the 4 methods
    init, start, stop and destroy part way through. I think you can prove
    this to yourself by putting a debug dump line at the head and tail of
    each of those methods.

    Applets are a bit hazy on who calls validate and repaint when.

    That may be where you are getting hammered.

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, Jun 18, 2004
    #5
  6. karambol

    karambol Guest


    > I find it highly unlikely the browser would abort any of the 4 methods
    > init, start, stop and destroy part way through. I think you can prove
    > this to yourself by putting a debug dump line at the head and tail of
    > each of those methods.


    I implemented stop() and destroy() and even finalize() methods in applet and
    threads. Those methods are not called if I exit the page too soon.

    There is more.. I put some debugging via System.out.print AND the Java
    console shows, that the applet recieves data from the server, and the
    threads are working, even though I clicked "back", and the applet is not
    even visible!

    It looks like the applet keeps initializing when the page is exited in a
    moment, when applet is not yet fully initialized. Or, that IE calls stop()
    after some period of time, which in this case is too long and IE can't call
    it because it's not on the "applet page" any more.

    --
    karambol
     
    karambol, Jun 18, 2004
    #6
  7. karambol

    karambol Guest


    > If your applet code launches any threads, then unless you have a really
    > good excuse not to, you should implement the stop method so that it stops
    > and destroys (by setting to null) the threads you launched.


    I implemented stop() and destroy(). The problem is, they are not being
    called, if i exit the page too soon (meaning: when the applet is being
    initialized or started).

    Try this:

    1. Create an applet with:

    start() {
    //some long initialization code here
    SomeThread t = new SomeThread();
    t.start();
    }

    2. In SomeThread.run put some debug info like:

    System.out.print("STILL HERE");
    sleep(100);

    3. Compile it, put on page, open in IE and move to another page just after
    opening the "Applet page", when you see this "java-style" gray rectangle
    instead of your applet content. The applet will keep initializing, the
    thread will start and be working, and the stop() will not be called. At
    least, this is what happened in my case.

    --
    karambol
     
    karambol, Jun 18, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt Theule

    Stop Debugging doesn't stop in ASP.NET

    Matt Theule, Jul 23, 2003, in forum: ASP .Net
    Replies:
    7
    Views:
    774
    Matt Theule
    Jul 24, 2003
  2. Son KwonNam
    Replies:
    11
    Views:
    2,646
    mr_organic
    Apr 9, 2004
  3. Will
    Replies:
    1
    Views:
    15,436
    Thomas Weidenfeller
    Nov 2, 2004
  4. crazytazo
    Replies:
    3
    Views:
    1,294
    Daniel Pitts
    Oct 7, 2008
  5. Angus
    Replies:
    5
    Views:
    477
    Ben Bacarisse
    Jul 18, 2010
Loading...

Share This Page