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

Chris Hegarty chris.hegarty at oracle.com
Tue May 21 15:58:48 UTC 2013


On 05/21/2013 06:07 AM, Mike Duigou wrote:

Looks good.

Since the char array is never modified it could use the String(char[], boolean) constructor. This has advantages for cases such as logging which may read the thread name very many times.

Thanks Mike, this would be a nice improvement.

Final webrev: http://cr.openjdk.java.net/~chegar/8010182/webrev.01/webrev/

-Chris.

Mike On May 18 2013, at 00: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/ -Chris. [1] http://cs.oswego.edu/pipermail/concurrency-interest/2013-March/010935.html



More information about the core-libs-dev mailing list