RFR 8010182: Thread safety of Thread get/setName() (original) (raw)

Alan Bateman Alan.Bateman at oracle.com
Tue May 21 07:58:09 UTC 2013


On 18/05/2013 08:57, Chris Hegarty wrote:

Thread getName and setName are not thread-safe. The "expected" usage is to set a name before starting the thread and only read it thereafter.

It is desirable to support the setting of thread name dynamically, mainly for monitoring/management/debugging. The typical scenario is the single-writer, multiple-reader case. So, making name volatile is sufficient. However, setName also sets the native thread name. This is currently restricted to the current thread, since there could be a race if the thread is terminating. Making setName synchronized would eliminate that race, and allow for the native thread name to be set from other threads. This issue came up on c-i a while back [1]. http://cr.openjdk.java.net/~chegar/8010182/webrev.00/webrev/ Looks fine to me too.

-Alan



More information about the core-libs-dev mailing list