We need a way to deal with the wacky situation where all threads created by an

applet are forcibly destroyed when it is destroyed, even though the applet's
class loader sticks around and it is started up again with the same classes
(which have already been static initialized). Twisty maze of passages.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@1939 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
mdb
2006-10-06 20:58:19 +00:00
parent b66931cd7f
commit 5457f286bc
+26 -5
View File
@@ -46,6 +46,20 @@ public abstract class Interval
public Interval getInterval ();
}
/**
* Clears out the {@link Timer} currently being used to schedule
* intervals. This method is normally not needed as a single timer thread
* can be used for the lifetime of the VM, but in certain situations (in
* applets) the timer thread will be forcibly killed when the applet is
* destroyed but the classes will not be unloaded. In that case, the applet
* should call this method in its own destroy method. A new timer thread
* will then be created the next time an interval is scheduled.
*/
public static synchronized void shutdown ()
{
_timer = null;
}
/**
* Create a simple interval that does not use a RunQueue to run
* the expired() method.
@@ -104,9 +118,9 @@ public abstract class Interval
_task = task;
if (repeatDelay == 0L) {
_timer.schedule(task, initialDelay);
getTimer().schedule(task, initialDelay);
} else {
_timer.scheduleAtFixedRate(task, initialDelay, repeatDelay);
getTimer().scheduleAtFixedRate(task, initialDelay, repeatDelay);
}
}
@@ -153,6 +167,14 @@ public abstract class Interval
}
}
protected static synchronized Timer getTimer ()
{
if (_timer == null) {
_timer = new Timer(/*JDK1.5 "samskivert Interval Timer",*/ true);
}
return _timer;
}
/**
* The task that schedules actually runs the interval.
*/
@@ -194,7 +216,6 @@ public abstract class Interval
/** The task that actually schedules our execution with the static Timer. */
protected volatile TimerTask _task;
/** The daemon timer used to schedule all Intervals. */
protected static final Timer _timer =
new Timer(/*JDK1.5 "samskivert Interval Timer",*/ true);
/** The daemon timer used to schedule all intervals. */
protected static Timer _timer;
}