jdk/src/share/classes/java/util/Timer.java
changeset 1006 f0e0218ff458
parent 2 90ce3da70b43
child 1014 335a6ba0adba
equal deleted inserted replaced
1005:1a39b4e3f2fc 1006:f0e0218ff458
    23  * have any questions.
    23  * have any questions.
    24  */
    24  */
    25 
    25 
    26 package java.util;
    26 package java.util;
    27 import java.util.Date;
    27 import java.util.Date;
       
    28 import java.util.concurrent.atomic.AtomicInteger;
    28 
    29 
    29 /**
    30 /**
    30  * A facility for threads to schedule tasks for future execution in a
    31  * A facility for threads to schedule tasks for future execution in a
    31  * background thread.  Tasks may be scheduled for one-time execution, or for
    32  * background thread.  Tasks may be scheduled for one-time execution, or for
    32  * repeated execution at regular intervals.
    33  * repeated execution at regular intervals.
   114             }
   115             }
   115         }
   116         }
   116     };
   117     };
   117 
   118 
   118     /**
   119     /**
   119      * This ID is used to generate thread names.  (It could be replaced
   120      * This ID is used to generate thread names.
   120      * by an AtomicInteger as soon as they become available.)
   121      */
   121      */
   122     private static AtomicInteger nextSerialNumber = new AtomicInteger(0);
   122     private static int nextSerialNumber = 0;
   123     private static int serialNumber() {
   123     private static synchronized int serialNumber() {
   124         return nextSerialNumber.getAndIncrement();
   124         return nextSerialNumber++;
       
   125     }
   125     }
   126 
   126 
   127     /**
   127     /**
   128      * Creates a new timer.  The associated thread does <i>not</i>
   128      * Creates a new timer.  The associated thread does <i>not</i>
   129      * {@linkplain Thread#setDaemon run as a daemon}.
   129      * {@linkplain Thread#setDaemon run as a daemon}.