You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Michal Bunarowski <mi...@comarch.pl> on 2010/03/05 09:17:22 UTC
class loaded twice when sharing wlfullclient.jar by two web apps
ClassCastException occurs in my web app, because classloaders load
the same class twice, when two web apps share WebLogic wlfullclient.jar.
Any idea how to avoid that? Details below.
Project set-up:
- Tomcat 6.0.13 + Weblogic 10.0
- wlfullclient.jar is placed in <TOMCAT_HOME>\lib.
- two web apps are deployed on Tomcat (WebApp1 & WebApp2).
The wep apps don't share any libraries except wlfullclient.jar.
- both web apps are subscribed to weblogic JMS topic.
Error scenario:
1. a message is generated in the weblogic JMS topic
2. both web apps retrieve the message
3. logic that handles the message in WepApp2 operates on a certain
class that belongs to WebApp2 (let's call the class "XXX" for convenience).
Namely, the logic contains casting:
Object xxxObject = someJndiLookup();
XXX someVariable = (XXX) xxxObject;
4. Casting results in ClassCastException. Debugging shows that
xxxObject is an object of the XXX class and its loaded by WebLogic
GenericClassLoader. And the object is cast to the XXX class
loaded by WebApp2ClassLoader.
Reason:
At the server startup, WebLogic GenericClassLoader (that is
provided within wlfullclient.jar) is loaded and it sets
WepApp1ClassLoader as its parent.
XXX class is a part of WepApp2 and obviously is loaded by
WepApp2ClassLoader.
When Weblogic JMS message comes up, GenericClassLoader has to deal
with an object of the XXX class. According to the classloaders
delegation model GenericClassLoader first asks its parent whether
the parent knows XXX. But - surprise - the parent of GenericClassLoader
is WepApp1ClassLoader. Obviously WepApp1ClassLoader does not know
this class, since it belongs to WebApp2. That's why GenericClassLoader
decides to load the class itself.
As a result there are multiple copies of the same class.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: class loaded twice when sharing wlfullclient.jar by two web apps
Posted by Konstantin Kolinko <kn...@gmail.com>.
2010/3/5 Michal Bunarowski <mi...@comarch.pl>:
>> > ClassCastException occurs in my web app, because classloaders load
>> > the same class twice, when two web apps share WebLogic
>> wlfullclient.jar.
>> > Any idea how to avoid that? Details below.
>>
>> Don't share the jar. Deploy a separate copy with each web application.
>
> We've been considering this. It solves the error indeed.
> But the problem is wlfullclient.jar has over 50 MB, so both
> WARs will increase a lot, which will have impact on our releases.
> So we were hoping there's some other solution.
>
Note, that there exists the following class:
http://tomcat.apache.org/tomcat-6.0-doc/api/org/apache/catalina/loader/VirtualWebappLoader.html
though it is not recommended for production.
Best regards,
Konstantin Kolinko
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: class loaded twice when sharing wlfullclient.jar by two web apps
Posted by Michal Bunarowski <mi...@comarch.pl>.
> > ClassCastException occurs in my web app, because classloaders load
> > the same class twice, when two web apps share WebLogic
> wlfullclient.jar.
> > Any idea how to avoid that? Details below.
>
> Don't share the jar. Deploy a separate copy with each web application.
We've been considering this. It solves the error indeed.
But the problem is wlfullclient.jar has over 50 MB, so both
WARs will increase a lot, which will have impact on our releases.
So we were hoping there's some other solution.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: class loaded twice when sharing wlfullclient.jar by two web apps
Posted by Mark Thomas <ma...@apache.org>.
On 05/03/2010 08:17, Michal Bunarowski wrote:
> ClassCastException occurs in my web app, because classloaders load
> the same class twice, when two web apps share WebLogic wlfullclient.jar.
> Any idea how to avoid that? Details below.
Don't share the jar. Deploy a separate copy with each web application.
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: class loaded twice when sharing wlfullclient.jar by two web apps
Posted by Michal Bunarowski <mi...@comarch.pl>.
> > Reason:
> > At the server startup, WebLogic GenericClassLoader (that is
> > provided within wlfullclient.jar) is loaded and it sets
> > WepApp1ClassLoader as its parent.
>
> Well that'll be your problem then. Why is it setting that classloader
> -
> what are you doing in WebApp1 to initialise the WebLogic stuff?
>
I do nothing explicitly. I guess WepApp1 simply starts up right before
WepApp2 and accesses wlfullclient.jar first. That seems to be enough
for GenericClassLoader to choose WebApp1ClassLoader as a parent.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: class loaded twice when sharing wlfullclient.jar by two web apps
Posted by Pid <pi...@pidster.com>.
On 05/03/2010 08:17, Michal Bunarowski wrote:
> ClassCastException occurs in my web app, because classloaders load
> the same class twice, when two web apps share WebLogic wlfullclient.jar.
> Any idea how to avoid that? Details below.
>
> Project set-up:
> - Tomcat 6.0.13 + Weblogic 10.0
> - wlfullclient.jar is placed in<TOMCAT_HOME>\lib.
> - two web apps are deployed on Tomcat (WebApp1& WebApp2).
> The wep apps don't share any libraries except wlfullclient.jar.
> - both web apps are subscribed to weblogic JMS topic.
>
> Error scenario:
> 1. a message is generated in the weblogic JMS topic
> 2. both web apps retrieve the message
> 3. logic that handles the message in WepApp2 operates on a certain
> class that belongs to WebApp2 (let's call the class "XXX" for convenience).
> Namely, the logic contains casting:
> Object xxxObject = someJndiLookup();
> XXX someVariable = (XXX) xxxObject;
> 4. Casting results in ClassCastException. Debugging shows that
> xxxObject is an object of the XXX class and its loaded by WebLogic
> GenericClassLoader. And the object is cast to the XXX class
> loaded by WebApp2ClassLoader.
>
> Reason:
> At the server startup, WebLogic GenericClassLoader (that is
> provided within wlfullclient.jar) is loaded and it sets
> WepApp1ClassLoader as its parent.
Well that'll be your problem then. Why is it setting that classloader -
what are you doing in WebApp1 to initialise the WebLogic stuff?
p
> XXX class is a part of WepApp2 and obviously is loaded by
> WepApp2ClassLoader.
> When Weblogic JMS message comes up, GenericClassLoader has to deal
> with an object of the XXX class. According to the classloaders
> delegation model GenericClassLoader first asks its parent whether
> the parent knows XXX. But - surprise - the parent of GenericClassLoader
> is WepApp1ClassLoader. Obviously WepApp1ClassLoader does not know
> this class, since it belongs to WebApp2. That's why GenericClassLoader
> decides to load the class itself.
> As a result there are multiple copies of the same class.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org