views:

38

answers:

3

hi, I am confused at a point while running my application. My application consists of EJB and servlets. i need to know, whether the class loader for these application types is same or different. I am using weblogic as application container. Please help me.

+1  A: 

You'll find that each application is typically loaded into it's own instance of a class loader. The class loader is going to be a class provided by the web container, but there will be one instance of it for each application running. This allows applications to be isolated from each other, and many instances to be loaded, regardless of whether they are using static/class variables, or singletons etc.

jowierun
@jowierun.. This means that class loader can be different for different application. But there is one master class loader viz. system class loader, which i feel remains same through the life time of the application. There is one class in my application which is singleton and class loader dependent.And the problem is that the instance of my class changes when class loader changes, and i need to use the same instance of the class through out the life time. And the above case is only possible if i use the same class loader. please help me.
Mrityunjay
Look at the link provided by Baski below. Search for `Packaging Shared Utility Classes`.
jowierun
+1  A: 

WebLogic uses layered class loader. How is your application packaged? Is it EAR or WAR + JAR's?

This link will be helpful.

Baski
+2  A: 

There is one class in my application which is singleton and class loader dependent.And the problem is that the instance of my class changes when class loader changes, and i need to use the same instance of the class through out the life time.

Yes there is a system classloader that all of the webapp classloaders will delegate to.

To get your class into that classloader, you need to make sure it is in the relevant classpath. For instance with Tomcat, you would put the JAR file into $CATALINA_HOME/lib (... if I'm remembering that correctly).

That having been said, I'm not convinced that sharing application singletons between multiple webapps is good design.

Stephen C