Google Groups Home
Help | Sign in
Message from discussion Performance characteristics of mutable static primitives?
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
John Rose  
View profile
 More options Apr 3, 7:01 pm
From: John Rose <John.R...@Sun.COM>
Date: Thu, 03 Apr 2008 16:01:54 -0700
Local: Thurs, Apr 3 2008 7:01 pm
Subject: Re: [jvm-l] Re: Performance characteristics of mutable static primitives?
On Apr 3, 2008, at 12:31 PM, John Cowan wrote:

> That reminds me of an old question of mine.  In the case where a
> thread has been created from an object whose class is a subclass of
> Thread, is Thread.currentThread() guaranteed to give you back the same
> object?

Yes.  You can then cast it to the subclass and go on from there.

> If so, that provides a different approach
> to thread-local state, where the state is held in the instance
> variables of MyThread objects, and the JVM is used to thread them
> through :-) the code until the point where they're needed.

That's how Java thread locals are implemented in the JVM.

You can only use this approach if (a) you control the creation of the  
thread and can specify your own subclass for it, or (b) you can edit  
the rt.jar code for java.lang.Thread.  Plan (c) is to make a  
ThreadLocal.

You might be interested to know that Hotspot intrinsifies  
Thread.currentThread to a couple of instructions; it's cheap.  We did  
that to make things like thread locals efficient.

Best,
-- John


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google