Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java: list thread locals?

Is there a way to list TheadLocals bound to a thread? Ideally I could access the Thread.threadLocals map, but it is package protected.

The reason I need this is I need to inspect threads as they are returned to a thread pool to ensure the ThreadLocals have been properly cleaned up. Perhaps there is another way to do this?

like image 427
Landon Kuhn Avatar asked Jan 04 '10 18:01

Landon Kuhn


1 Answers

Listing ThreadLocals and Clearing ThreadLocals can be accomplished by using reflection (and the setAccessible() flag) to override the JVM's usual permissions. For obvious reasons, this not available when all security mechanisms are in place.

like image 53
jarekrozanski Avatar answered Oct 04 '22 15:10

jarekrozanski