Summary
Change the default thread pool used by asynchronous channels in java.nio.channels
to be "innocuous threads", meaning they don't inherit the thread-context-class-loader or inheritable-ThreadLocals from the caller thread.
Problem
The asynchronous channels in java.nio.channels
(AsynchronousSocketChannel, AsynchronousFileChannel, ..) allow a completion handler to be invoked when an I/O operation completes. The thread pool used to invoke completion handlers is configurable but when not specified, a default thread pool is used. At things stand, the threads in this default pool will inherit the thread-context-class-loader and any inheritable-ThreadLocals from the caller thread, usually a thread that initiates an I/O operation.
This inheritance can lead to memory leak / retention issues, say when a caller thread has a large graph of objects reachable via its TCCL. If inherited into a thread in the default thread pool then this graph of objects will remain reachable after the original caller thread has terminated.
Solution
Make the change described in the Summary section above. The proposed new behavior (to not inherit) aligns the implementation with past behavior when running with a SecurityManager.
Specification
There are no specification changes.
- csr of
-
JDK-8345432 (ch, fs) Replace anonymous Thread with InnocuousThread
- In Progress