Skip to main content

AppletContext.setStream doesn't save the stream when the browser is closed

3 replies [Last post]
Joined: 2003-10-04

I wanted to use AppletContext.setStream and getStream in order to remember the changed settings of the applet between 2 usages.

setStream is in Applet.close() and getStream is in Applet.start()
What I've discovered is that if I go to another page and come back to my applet page then the stream is saved correctly but if I close the browser and come back to the page getStream(key) returns null.

I've created an small example with source code:

This happens with IE and Firefox, Java 6u10 and 6u7.

Is it a bug or is it normal?


Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2008-03-14

Starting around the release of 1.6, SUN changed the whole lifecycle of an applet.

stop() and destroy() are practically valueless and there is no guarantee that the JVM will stay alive even if you only change pages.

The JVM is terminated seemingly at random.

Previously, with the old applet lifecycle, you could store state in static variables and use your method reliably -- you just can't do that anymore regardless of what the documentation says.

SUN did major damage to Java in the last two or three years it worked on it.

Joined: 2003-06-19

AppletContext makes no guarantees about the persistence of streams. In Sun's JREs streams are simply implemented as lasting as long as the context.

With the new plugin, I believe you can use the JNLP persistence service to store small amounts of data (around 128K, IIRC).

Joined: 2005-06-21

> AppletContext makes no guarantees about the
> persistence of streams.


This is not entirely true. The documentation of the current java version clearly says:

"AppletContext allow[s] applet persistence across browser sessions."