Are you sure you actually want thread local scope? It's very prone to memory leaks.
Bob
I could see some possibility of issues if your thread pools shrink and
grow, but as long as the references are traversable and self contained
not bound to any long lived object, the weak references in the map
should work as expected, correct?
-bp
Is this still true in an environment that can be configured with fixed
thread pools such as servlet containers and such? I was under the
impression that the Map used was keyed off the thread ID and that was
fixed. Plus I also thought they were all weak references.
I could see some possibility of issues if your thread pools shrink and
grow, but as long as the references are traversable and self contained
not bound to any long lived object, the weak references in the map
should work as expected, correct?
-bp
On Sep 30, 2008, at 4:59 PM, Bob Lee wrote:
> Are you sure you actually want thread local scope? It's very prone
> to memory leaks.
>
> Bob
>
> >
I could see some possibility of issues if your thread pools shrink and
grow, but as long as the references are traversable and self contained
not bound to any long lived object, the weak references in the map
should work as expected, correct?
Right. That's what I was referring to here:"Therefore, if you set the pointer, forget to clear it, check into the pool and then check out again, once the thread comes out of the pool that pointer is still valid and if you replace it, they old value is available for GC."That still doesn't mean a leak unless the pointer references an object that continues to grow and is never cleared.
Definitely really nasty, but worse.... that's debatable. VMs don't
like OutOfMemoryErrors much. All those other application errors, they
don't mind so much. ;)
-bp
Right. That was my only point really. :)
-bp
-bp
Been thinking on this stuff a bit this morning and I think I could
remove my ThreadLocals and put stuff in a Request scope for my
webapps. As long as I could figure out a way to lazy load from the
scope since I have some cases where I inject something that requires
an EntityManager (for example) before the EntityManager is setup.