8010182: Thread safety of Thread get/setName()
Reviewed-by: dholmes, alanb, mduigou
--- 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);
}
/**