Xiaobin Lu said the following on 08/11/10 08:07:
Thanks for your reply. For a lot of enterprise applications (such as the
one I work for), a fair amount of time goes to that Thread.setName call
which I believe a significant portion is to do new char allocation and
copy char array etc. So I think we should give a second thought about
how we can efficiently store that field.
There was an RFE for this way back in late 2002:
4745629 (thread) Thread.setName does needless string allocations (don't
use char[])
The initial eval in 2002 stated:
"I can't imagine that this seriously impacts the performance of any real
program. Furthermore, changing the fields in Thread is problematic due
to the close relationship of this class with the VM. That said, it
might be worth addressing this in the context of some Thread code-cleanup."
Then in 2005 it was closed as "will not fix":
"There are dependencies on the name representation being a char array in
the JVM and this RFE must be respectfully rejected."
---
Changing both the VM and the Java code is, as you know, a real pain to
coordinate, so there would have to be some compelling performance
evidence to support this (assuming it can be changed). Personally I
agree with the initial eval above - if setName is impacting your overall
performance then your threads can not be doing too much real work and
you would seem to be creating far too many threads - so I'd be
interested to here more about the context in which this occurs.
Of course you are quite welcome to investigate whether such a change is
feasible. ;-)
Cheers,
David
-Xiaobin
On Tue, Aug 10, 2010 at 3:00 PM, David Holmes <[email protected]
<mailto:[email protected]>> wrote:
Hi Xiaobin,
Xiaobin Lu said the following on 08/11/10 07:42:
Would anyone please let me know why we convert the incoming
argument of Thread.setName() to a char array? Why can't we just
store the incoming argument to the name since String is
immutable anyways?
I know I've wondered the same thing in the past, and I can't recall
the exact details of what I determined at the time. The only thing I
presently recall is that the name is accessed directly from VM code
(internally and things like JVMTI) - hence a raw char array is
easier to access than a String object.
David