Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > IE does not call stop() on applet

Reply
Thread Tools

IE does not call stop() on applet

 
 
karambol
Guest
Posts: n/a
 
      06-18-2004
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
 
Reply With Quote
 
 
 
 
Liz
Guest
Posts: n/a
 
      06-18-2004

"karambol" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.


 
Reply With Quote
 
 
 
 
karambol
Guest
Posts: n/a
 
      06-18-2004

> 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
 
Reply With Quote
 
Liz
Guest
Posts: n/a
 
      06-18-2004

"karambol" <(E-Mail Removed)> wrote in message
news:40d29604$(E-Mail Removed)...
>
> > 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.




 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      06-18-2004
On Fri, 18 Jun 2004 09:13:34 +0200, karambol <(E-Mail Removed)>
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.
 
Reply With Quote
 
karambol
Guest
Posts: n/a
 
      06-18-2004

> 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
 
Reply With Quote
 
karambol
Guest
Posts: n/a
 
      06-18-2004

> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
When Javascript call applet method, applet throw security exception. crazytazo Java 3 10-06-2008 11:12 PM
Java Applet loading in Applet Viewer but not in HTML page Archana Java 1 10-24-2004 11:41 PM
Re: newbie: Join JApplet & Applet in one applet Andrew Thompson Java 0 08-05-2003 01:41 PM
Re: play wave files using java.applet.Applet webster Java 0 07-20-2003 01:51 PM
applet vs. canvas in applet Rob Love Java 1 07-07-2003 10:07 PM



Advertisments