[concurrency-interest] Thread safety of Thread.getName()

Zhong Yu zhong.j.yu at gmail.com
Thu Mar 14 17:21:53 EDT 2013


java.lang.Thread

    private char name[];

    public final void setName(String name) {
        checkAccess();
        this.name = name.toCharArray();
    }

    public final String getName() {
        return String.valueOf(name);
    }

On the surface, set/getName() are not correctly synchronized,
getName() could observe a partially filled char array. What's the
story here?

Zhong Yu


More information about the Concurrency-interest mailing list