is the class loader for different application can be different?
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 开发者_JAVA技巧container. Please help me.
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.
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.
WebLogic uses layered class loader. How is your application packaged? Is it EAR or WAR + JAR's?
This link will be helpful.
精彩评论