Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8172726

ForkJoin common pool retains a reference to the thread context class loader

    Details

      Backports

        Description

        FULL PRODUCT VERSION :
        java version "1.8.0_112"
        Java(TM) SE Runtime Environment (build 1.8.0_112-b15)
        Java HotSpot(TM) 64-Bit Server VM (build 25.112-b15, mixed mode)

        ADDITIONAL OS VERSION INFORMATION :
        Microsoft Windows [Version 6.1.7601] (fully patched)

        A DESCRIPTION OF THE PROBLEM :
        There are multiple issues with ForkJoinPool.commonPool

        1. The default thread pool does not change Thread.contextClassLoader to the system class loader. When ForkJoinPool.commonPool is used in a multi-class loader environment (e.g. a JavaEE container) this causes references to be retained to the class loader associated with the code that first uses the pool. This is highly likely to cause a memory leak.

        2. The InnocuousForkJoinWorkerThread does not modify Thread.contextClassLoader so undesirable class loader references are retained even when using the InnocuousForkJoinWorkerThreadFactory

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Execute this test case:

        https://github.com/markt-asf/memory-leaks/blob/master/src/org/apache/markt/leaks/concurrent/ForkJoinThreadLeak.java

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        The console should report no leaks detected.
        ACTUAL -
        The console reports that a memory leak is detected and use of a profiler confirms the leak.

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        https://github.com/markt-asf/memory-leaks/blob/master/src/org/apache/markt/leaks/concurrent/ForkJoinThreadLeak.java
        ---------- END SOURCE ----------

        1. ForkJoinThreadLeak.java
          2 kB
          Abdul Kolarkunnu
        2. LeakBase.java
          2 kB
          Abdul Kolarkunnu
        3. RelaxedClassLoader.java
          0.6 kB
          Abdul Kolarkunnu

          Issue Links

            Activity

            Hide
            chegar Chris Hegarty added a comment -
            Although somewhat of a lesser issue, do we want to update the TCCL in ThreadPerTaskExecutor, for consistency?
            Show
            chegar Chris Hegarty added a comment - Although somewhat of a lesser issue, do we want to update the TCCL in ThreadPerTaskExecutor, for consistency?
            Hide
            martin Martin Buchholz added a comment -
            Still distracted, but still trying to get something out today ...
            Show
            martin Martin Buchholz added a comment - Still distracted, but still trying to get something out today ...
            Show
            martin Martin Buchholz added a comment - http://cr.openjdk.java.net/~martin/webrevs/openjdk9/jsr166-jdk9-integration/common-pool/
            Hide
            hgupdate HG Updates added a comment -
            URL: http://hg.openjdk.java.net/jdk9/dev/jdk/rev/7d64e541a6c0
            User: martin
            Date: 2017-02-07 09:20:56 +0000
            Show
            hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/dev/jdk/rev/7d64e541a6c0 User: martin Date: 2017-02-07 09:20:56 +0000
            Hide
            hgupdate HG Updates added a comment -
            URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/7d64e541a6c0
            User: lana
            Date: 2017-02-08 19:31:50 +0000
            Show
            hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/7d64e541a6c0 User: lana Date: 2017-02-08 19:31:50 +0000

              People

              • Assignee:
                martin Martin Buchholz
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                11 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: