Promptly freeing the per-thread cached direct buffers when a thread exits

David Lloyd david.lloyd at
Thu Apr 5 22:23:30 UTC 2018

On Thu, Apr 5, 2018 at 4:45 PM, Tony Printezis <tprintezis at> wrote:
> Would proposing to introduce thread exit hooks be reasonable? Or is
> everyone going to freak out? :-) The hooks can be either per-Thread or even
> per-ThreadLocal. And it's OK if the hooks can only be used within java.base.

User-accessible thread exit hooks would be nice, from a user
perspective.  From a JDK perspective - it adds new opportunities for
user code to jam things up, so it's a tradeoff.

ThreadLocal clearing on thread exit would have been nice back in the
beginning, but now I think it would be a fairly substantial behavior
change.  Adding a new exit() method on ThreadLocal would be better
(but not perfect) compatibility-wise, and see prior note about users
jamming things up...

I think that at a minimum, explicitly releasing thread-local NIO
direct buffers on thread exit (without introducing a user facing API)
is probably safe.  Some kind of user-accessible hook would be nice,
but I can't imagine it would take anything less than a massive
discussion to get there.


More information about the core-libs-dev mailing list