changeset 471:3a1325be2806

6730380: java.util.Timer should use AtomicInteger Reviewed-by: dl, chegar
author martin
date Fri, 01 Aug 2008 00:38:02 -0700
parents 98caad5c563c
children f33c3846cecb
files src/share/classes/java/util/Timer.java
diffstat 1 files changed, 5 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/util/Timer.java	Thu Jul 31 17:38:55 2008 +0200
+++ b/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();
     }
 
     /**