Re: Proposed new Java feature
On 05/28/2012 12:20 AM, markspace wrote:
On 5/27/2012 2:51 PM, Eric Sosman wrote:
I understood it fine the first time around, thanks. If you
think of anything new to add, pray do so.
This is uncharitable. In particular because I think his point went
whooshing over your head, and you didn't understand it at all.
He's saying the thread is done. Kaput. Any Sioux Unusual class using the
thread will loose its thread locals, because at this point it expects
the thread to die.
How can you know if you did not create the thread? If the thread dies
as in "terminates and then is GC'ed" there is no need for additional
cleanup because GC will do that just fine.
So instead of allowing the thread to die, we re-use it. But what would
Sioux Unusual do? How would it expect this thread to be matched up with
the same object ever again? There's no guarantee of that. Thread
assignment from the executor is random. Worse, another Sioux Unusual
object could see the thread local from some different object, and assume
it's been assigned from its own invocation, when it clearly hasn't.
Really, the problem is that Sioux Unusual is broken for this
application, and shouldn't be used when threads are gong to be re-used
and randomly reassigned. But that's not what he's talking about. He's
talking about the case where he doesn't need the thread locals to
persist, but he does need to use them, and to release them too.
But he cannot know how long ThreadLocals need to stay which are not
created in his code. If cleanup is needed then it must be done per
ThreadLocal and never globally.
The posts by myself and Tom should indicate that Mike is not alone in
this need. He's got a real problem. That you insist that his
requirements should be obviated because you or someone else might have
some different requirement... well that just doesn't make sense.
If there is a real problem then it's not using ThreadLocal properly.
That should be fixed. And not a dangerous functionality added to
standard library where changes are enormous to wreck havoc on all sorts
of code.
Kind regards
robert