8010182: Thread safety of Thread get/setName()

Reviewed-by: dholmes, alanb, mduigou
This commit is contained in:
Chris Hegarty 2013-05-22 13:50:53 +01:00
parent eb6c8c5bc8
commit 64b3efd73b

View File

@ -145,7 +145,7 @@ class Thread implements Runnable {
registerNatives();
}
private char name[];
private volatile char name[];
private int priority;
private Thread threadQ;
private long eetop;
@ -1135,7 +1135,7 @@ class Thread implements Runnable {
* @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 @@ class Thread implements Runnable {
* @see #setName(String)
*/
public final String getName() {
return String.valueOf(name);
return new String(name, true);
}
/**