title: Memory leak on Tomcat 7 with Oracle JDBC drivers 12c - oracle.jdbc.driver thread failed to stop
body: <p>I have a web app deployed to Tomcat 7.0.54 that uses a datasource to connect to an Oracle 11g database. The datasource is configured in <code>META-INF/context.xml</code> and I've placed ojdbc7.jar in <code>&lt;tomcat-install-dir&gt;/lib</code>. I use a JNDI lookup to retrieve the datasource which I store in a singleton so that each DAO class can use it.</p>
  
  <p>Everything works as expected, however when I undeploy the application (via Tomcat manager app) I see in the logs:</p>
  
  <pre><code>Oct 03, 2014 3:06:55 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
  SEVERE: The web application [/myapp] appears to have started a thread named [oracle.jdbc.driver.BlockSource.ThreadedCachingBlockSource.BlockReleaser] but has failed to stop it. This is very likely to create a memory leak.
  Oct 03, 2014 3:06:57 PM org.apache.catalina.startup.HostConfig undeploy
  INFO: Undeploying context [/myapp]
  </code></pre>
  
  <p>When I debug I can see this thread gets created as soon as the database is accessed (via the datasource).</p>
  
  <p>My datasource config:</p>
  
  <pre><code>&lt;Context antiResourceLocking="false"&gt;
      &lt;Resource name="jdbc/myapp" auth="Container" 
          type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver" 
          maxActive="20" maxIdle="10" maxWait="-1"
          username="myuser" password="mypass"
          url="jdbc:oracle:thin:@myserver:1521:mysid"
          removeAbandoned="true" removeAbandonedTimeout="10" logAbandoned="true"
          validationQuery="SELECT 1 FROM DUAL"   
          testOnBorrow="true" testOnReturn="true" testWhileIdle="true"  
          timeBetweenEvictionRunsMillis="1800000" numTestsPerEvictionRun="3"  
          minEvictableIdleTimeMillis="1800000"
      /&gt;
  &lt;/Context&gt;
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>Further investigation has revealed that the issue occurs whether or not the datasource is accessed during application (or servlet) initialisation.</p>
  
  <p>In actual fact, the problematic thread is only created, and thus the issue only exists, when using the 12c versions of Oracle's JDBC drivers (either ojdbc6.jar or ojdbc7.jar).</p>
  
  <p>If I revert to using the 11.2.0.4 version of ojdbc6.jar the thread is never created and the memory leak warning never appears.</p>
  
  <p>Should I downgrade JDBC driver (as suggested in <a href="https://stackoverflow.com/a/9177263/4105953">https://stackoverflow.com/a/9177263/4105953</a>)?</p>