On 4/3/08, John Cowan <[EMAIL PROTECTED]> wrote:
>
> On Thu, Apr 3, 2008 at 7:01 PM, John Rose <[EMAIL PROTECTED]> wrote:
>
> > Yes. You can then cast it to the subclass and go on from there.
>
>
> That's what I had hoped, but the JLS doesn't actually seem to guarantee this.
>
>
> > > 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.
>
>
> I don't understand how that can be, as I can create as many
> ThreadLocals as I want. They can't all fit in the Thread object,
> surely. And how can reference to them be fast if they have to
> indirect through a Thread subclass object?
the source for ThreadLocal explains the first bit:
public void set(T value) {
Thread t = Thread.currentThread();
ThreadLocalMap map = getMap(t);
if (map != null)
map.set(this, value);
else
createMap(t, value);
}
apparently, every thread has a map that holds all ThreadLocal's registered
>
>
> > You can only use this approach if (a) you control the creation of the
> > thread and can specify your own subclass for it,
>
>
> That's what I had in mind.
>
>
> > 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.
>
>
> Good.
>
>
> --
> GMail doesn't have rotating .sigs, but you can see mine at
> http://www.ccil.org/~cowan/signatures
>
> >
>
--
[]'s
Marcelo Takeshi Fukushima
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "JVM
Languages" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/jvm-languages?hl=en
-~----------~----~----~----~------~----~------~--~---