eXist-db / exist

eXist Native XML Database and Application Platform
https://exist-db.org
GNU Lesser General Public License v2.1
416 stars 179 forks source link

Java 9 Reflection, and ThreadLocal cleanup #1891

Open adamretter opened 6 years ago

adamretter commented 6 years ago

We have a warning with regards IllegalReflectiveAccess in BrokerPool on Java 9+.

This comes about due to BrokerPoool#cleanThreadLocalsForThread(Thread) which uses reflection to manually clear out thread-locals. This code was added as we seemed to have a problem with some ThreadLocals never being cleared, which prohibited a clean shutdown when running eXist-db inside a Servlet Container such as Tomcat.

I suspect, the real cause of the ThreadLocal leak is potentially anywhere where we have used ThreadLocal from a DBBroker (which is a reused Thread). See - https://www.javaspecialists.eu/archive/Issue229.html

If we fix those issues, we could drop BrokerPoool#cleanThreadLocalsForThread(Thread).

The first thing that needs to be examined is org.exist.collections.triggers.TriggerStatePerThread. I don't quite understand why it is needed at the moment. It seems completely superfluous. The second thing that needs examining are ByteArrayPool and it's friends, which also use ThreadLocal.

adamretter commented 6 years ago

This also seems to be related - https://github.com/eXist-db/exist/issues/1947