6730380: java.util.Timer should use AtomicInteger
authormartin
Fri, 01 Aug 2008 00:38:02 -0700
changeset 1006 f0e0218ff458
parent 1005 1a39b4e3f2fc
child 1007 72a8a27e1d69
6730380: java.util.Timer should use AtomicInteger Reviewed-by: dl, chegar
jdk/src/share/classes/java/util/Timer.java
--- 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();
     }
 
     /**