jdk/src/share/classes/java/util/Timer.java
changeset 1014 335a6ba0adba
parent 1006 f0e0218ff458
child 1247 b4c26443dee5
--- a/jdk/src/share/classes/java/util/Timer.java	Wed Aug 06 10:49:31 2008 -0700
+++ b/jdk/src/share/classes/java/util/Timer.java	Thu Aug 07 06:36:41 2008 -0700
@@ -93,12 +93,12 @@
      * and the timer thread consumes, executing timer tasks as appropriate,
      * and removing them from the queue when they're obsolete.
      */
-    private TaskQueue queue = new TaskQueue();
+    private final TaskQueue queue = new TaskQueue();
 
     /**
      * The timer thread.
      */
-    private TimerThread thread = new TimerThread(queue);
+    private final TimerThread thread = new TimerThread(queue);
 
     /**
      * This object causes the timer's task execution thread to exit
@@ -107,7 +107,7 @@
      * Timer as such a finalizer would be susceptible to a subclass's
      * finalizer forgetting to call it.
      */
-    private Object threadReaper = new Object() {
+    private final Object threadReaper = new Object() {
         protected void finalize() throws Throwable {
             synchronized(queue) {
                 thread.newTasksMayBeScheduled = false;
@@ -119,7 +119,7 @@
     /**
      * This ID is used to generate thread names.
      */
-    private static AtomicInteger nextSerialNumber = new AtomicInteger(0);
+    private final static AtomicInteger nextSerialNumber = new AtomicInteger(0);
     private static int serialNumber() {
         return nextSerialNumber.getAndIncrement();
     }
@@ -387,6 +387,11 @@
         if (time < 0)
             throw new IllegalArgumentException("Illegal execution time.");
 
+        // Constrain value of period sufficiently to prevent numeric
+        // overflow while still being effectively infinitely large.
+        if (Math.abs(period) > (Long.MAX_VALUE >> 1))
+            period >>= 1;
+
         synchronized(queue) {
             if (!thread.newTasksMayBeScheduled)
                 throw new IllegalStateException("Timer already cancelled.");