jdk/src/share/classes/java/util/Timer.java
changeset 1006 f0e0218ff458
parent 2 90ce3da70b43
child 1014 335a6ba0adba
--- a/jdk/src/share/classes/java/util/Timer.java	Thu Jul 31 17:38:55 2008 +0200
+++ b/jdk/src/share/classes/java/util/Timer.java	Fri Aug 01 00:38:02 2008 -0700
@@ -25,6 +25,7 @@
 
 package java.util;
 import java.util.Date;
+import java.util.concurrent.atomic.AtomicInteger;
 
 /**
  * A facility for threads to schedule tasks for future execution in a
@@ -116,12 +117,11 @@
     };
 
     /**
-     * This ID is used to generate thread names.  (It could be replaced
-     * by an AtomicInteger as soon as they become available.)
+     * This ID is used to generate thread names.
      */
-    private static int nextSerialNumber = 0;
-    private static synchronized int serialNumber() {
-        return nextSerialNumber++;
+    private static AtomicInteger nextSerialNumber = new AtomicInteger(0);
+    private static int serialNumber() {
+        return nextSerialNumber.getAndIncrement();
     }
 
     /**