Different Behavior of the Thread Context Classloader with JDK 1.4 and JDK 1.5 (Doc ID 453373.1)

Last updated on NOVEMBER 01, 2016

Applies to:

Oracle Containers for J2EE - Version 10.1.3.1.0 to 10.1.3.2.0 [Release AS10gR3]
Information in this document applies to any platform.

Symptoms

Using JDK 1.4 and JDK 1.5 with OC4J 10.1.3.1 or 10.1.3.2 leads to different results:

There is a different behavior of the Thread Context ClassLoader with different versions of JDK.

With JDk 1.5, Thread Context ClassLoader (received from Thread.currentThread().getContextClassLoader()) in all threads is the same ClassLoader instance as the current ClassLoader (received from getClass().getClassLoader()).

With JDK 1.4, Thread Context ClassLoader (in the threads, created by application) is NOT the same ClassLoader instance as the current ClassLoader. It is even the instance of a different Class.

You can reproduce the issue by running the “TestLoaders” Web Application.

This application has Start-up Servlet, creates one thread and one Timer Task.

It has three “check points” :
– in Start-up Servlet (thread created by OC4J)
- in the Tread (created by our application)
- in the Timer Task

At each point it is checking if Thread Context ClassLoader is the same ClassLoader instance as the current ClassLoader and printing Class Loaders (including “parents”).

In addition it checks if the correct parser is accessed (should be xerces, which is in the Web App classpath and for which we added a shared library).

Download the testcase(rename to .war) by clicking here


I. WITH JDK 1.5
++++++++++++++++

1. Start OC4J 10.1.3.2.0 from the command line:

java -Xms128m -Xmx1024m -jar oc4j.jar -userThreads

2. Create a shared library xerces to use a xerces parser, as it is recommended by Oracle to use this parser
(Example: Replacing the Oracle XML Parser with the Xerces Parser - http://docs.oracle.com/cd/B31017_01/web.1013/b28952/classload.htm).

3. Deploy TestLoaders.war.

During deployment for Web Module set (using console or by files modification):
<web-app-class-loader search-local-classes-first="true" />, <remove-inherited name="oracle.xml"/>, <import-shared-library name="xerces"/>

OUTPUT WITH JDK 1.5
+++++++++++++++++++

2007-05-09 12:07:22.312 NOTIFICATION Initializing Servlet: com.taxware.twe.common.storage.StrtServlet for web application TestLoaders
07/05/09 12:07:22 ------In StartupServlet Init-----
07/05/09 12:07:22 +++++++ ++++++++++++++++++++++++++++++++++++ ++++++++
07/05/09 12:07:22 +++++++ Executing Code in the StrtServlet... ++++++++
07/05/09 12:07:22 +++++++ (this Thread created by App Server) +++++++++
07/05/09 12:07:22 ClassLoaders: fromClass = getClass().getClassLoader() = <TestLoaders.web.TestLoaders:0.0.0>*******
07/05/09 12:07:22 fromThread =Thread.currentThread().getContextClassLoader() = <TestLoaders.web.TestLoaders:0.0.0>*******
07/05/09 12:07:22 ******* THE SAME CLASSLOADER USED IN BOTH PLACES!!! *******
07/05/09 12:07:22 DocumentBuilderFactory = <org.apache.xerces.jaxp.DocumentBuilderFactoryImpl@14c803d>*******
07/05/09 12:07:22 -CWD- =D:\OC4J\OC4J10132\j2ee\home; uer directory = D:\OC4J\OC4J10132\j2ee\home
07/05/09 12:07:22 Constructing the Timer Task...
07/05/09 12:07:22 Starting some Timer...
07/05/09 12:07:22 Some Timer is started ...
07/05/09 12:07:22 ------All actions done Successfully--------
2007-05-09 12:07:22.328 NOTIFICATION Binding web application(s) to site default-web-site ends...
2007-05-09 12:07:22.343 NOTIFICATION Application Deployer for TestLoaders COMPLETES. Operation time: 687 msecs
07/05/09 12:08:22 +++++++ +++++++++++++++++++++++++++++++++++ ++++++++
07/05/09 12:08:22 +++++++ Executing the Session Timer Task... ++++++++
07/05/09 12:08:22 ClassLoaders: fromClass = getClass().getClassLoader() = <TestLoaders.web.TestLoaders:0.0.0>*******
07/05/09 12:08:22 fromThread =Thread.currentThread().getContextClassLoader() = <TestLoaders.web.TestLoaders:0.0.0>*******
07/05/09 12:08:22 ******* THE SAME CLASSLOADER USED IN BOTH PLACES!!! *******
07/05/09 12:08:22 DocumentBuilderFactory = <org.apache.xerces.jaxp.DocumentBuilderFactoryImpl@17a0b4d>*******


**AS CAN BE SEEN, org.apache.xerces.jaxp.DocumentBuilderFactoryImpl@17a0b4d IS PICKED UP**

II. WITH JDK 1.4
+++++++++++++++++

1. Start OC4J 10.1.3.2.0 from the command line:

java -Xms128m -Xmx1024m -jar oc4j.jar -userThreads

2. Create a shared library xerces to use a xerces parser, as it is recommended by Oracle to use this parser
(Example: Replacing the Oracle XML Parser with the Xerces Parser - http://docs.oracle.com/cd/B31017_01/web.1013/b28952/classload.htm).

3. Deploy TestLoaders.war.

During deployment for Web Module set (using console or by files modification):
<web-app-class-loader search-local-classes-first="true" />, <remove-inherited name="oracle.xml"/>, <import-shared-library name="xerces"/>

OUTPUT WITH JDK 1.4
+++++++++++++++++++

D:\OC4J\OC4J10132\bin>oc4j -start
Starting OC4J from D:\OC4J\OC4J10132\j2ee\home ...
07/05/09 12:31:17 ------In StartupServlet Init-----
07/05/09 12:31:17 +++++++ ++++++++++++++++++++++++++++++++++++ ++++++++
07/05/09 12:31:17 +++++++ Executing Code in the StrtServlet... ++++++++
07/05/09 12:31:17 +++++++ (this Thread created by App Server) +++++++++
07/05/09 12:31:17 ClassLoaders: fromClass = getClass().getClassLoader() = <TestL
oaders.web.TestLoaders:0.0.0>*******
07/05/09 12:31:17 fromThread =Thread.currentThread().getContextCla
ssLoader() = <TestLoaders.web.TestLoaders:0.0.0>*******
07/05/09 12:31:17 ******* THE SAME CLASSLOADER USED IN BOTH PLACES!!! *******
07/05/09 12:31:17 DocumentBuilderFactory = <org.apache.xerces.jaxp.DocumentBuild
erFactoryImpl@efae3b>*******
07/05/09 12:31:17 -CWD- =D:\OC4J\OC4J10132\bin; uer directory = D:\OC4J\OC4J1013
2\bin
07/05/09 12:31:17 Constructing the Timer Task...
07/05/09 12:31:17 Starting some Timer...
07/05/09 12:31:17 Some Timer is started ...
07/05/09 12:31:17 ------All actions done Successfully--------
07/05/09 12:31:17 Oracle Containers for J2EE 10g (10.1.3.2.0) initialized
07/05/09 12:32:17 +++++++ +++++++++++++++++++++++++++++++++++ ++++++++
07/05/09 12:32:17 +++++++ Executing the Session Timer Task... ++++++++
07/05/09 12:32:17 ClassLoaders: fromClass = getClass().getClassLoader() = <TestL
oaders.web.TestLoaders:0.0.0>*******
07/05/09 12:32:17 fromThread =Thread.currentThread().getContextCla
ssLoader() = <[ThreadContextLoader, current context: system.root:0.0.0]>*******
07/05/09 12:32:17 **************************************************
07/05/09 12:32:17 Chain of ClassLoaders from Class
07/05/09 12:32:17 --- TestLoaders.root:0.0.0
07/05/09 12:32:17 --- default.root:0.0.0
07/05/09 12:32:17 --- system.root:0.0.0
07/05/09 12:32:17 --- oc4j:10.1.3
07/05/09 12:32:17 --- api:1.4.0
07/05/09 12:32:17 --- jre.extension:0.0.0
07/05/09 12:32:17 --- jre.bootstrap:1.4.2_06
07/05/09 12:32:17 --- null
07/05/09 12:32:17 ********** End of Chain of ClassLoaders **********
07/05/09 12:32:17 **************************************************
07/05/09 12:32:17 Chain of ClassLoaders from Thread
07/05/09 12:32:17 --- oc4j:10.1.3
07/05/09 12:32:17 --- api:1.4.0
07/05/09 12:32:17 --- jre.extension:0.0.0
07/05/09 12:32:17 --- jre.bootstrap:1.4.2_06
07/05/09 12:32:17 --- null
07/05/09 12:32:17 ********** End of Chain of ClassLoaders **********
07/05/09 12:32:17 DocumentBuilderFactory = <oracle.xml.jaxp.JXDocumentBuilderFactory@181efb9>*******




**AS CAN BE SEEN, oracle.xml.jaxp.JXDocument BuilderFactory@181efb9 IS PICKED UP INSTEAD OF org.apache.xerces.jaxp.DocumentBuilderFactoryImpl@17a0b4d**

Cause

Sign In with your My Oracle Support account

Don't have a My Oracle Support account? Click to get started

My Oracle Support provides customers with access to over a
Million Knowledge Articles and hundreds of Community platforms