8010182: Thread safety of Thread get/setName()
authorchegar
Wed, 22 May 2013 13:50:53 +0100
changeset 17704 dab42001bbe0
parent 17703 628f27618a6a
child 17705 b50b9139c47e
child 17706 c63d8676af01
8010182: Thread safety of Thread get/setName() Reviewed-by: dholmes, alanb, mduigou
jdk/src/share/classes/java/lang/Thread.java
--- a/jdk/src/share/classes/java/lang/Thread.java	Tue May 21 01:50:13 2013 -0700
+++ b/jdk/src/share/classes/java/lang/Thread.java	Wed May 22 13:50:53 2013 +0100
@@ -145,10 +145,10 @@
         registerNatives();
     }
 
-    private char        name[];
-    private int         priority;
-    private Thread      threadQ;
-    private long        eetop;
+    private volatile char  name[];
+    private int            priority;
+    private Thread         threadQ;
+    private long           eetop;
 
     /* Whether or not to single_step this thread. */
     private boolean     single_step;
@@ -1135,7 +1135,7 @@
      * @see        #getName
      * @see        #checkAccess()
      */
-    public final void setName(String name) {
+    public final synchronized void setName(String name) {
         checkAccess();
         this.name = name.toCharArray();
         if (threadStatus != 0) {
@@ -1150,7 +1150,7 @@
      * @see     #setName(String)
      */
     public final String getName() {
-        return String.valueOf(name);
+        return new String(name, true);
     }
 
     /**