tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Cotton, Joseph B" <bcot...@dpscs.state.md.us>
Subject RE: Wish to use an independent class module in Tomcat
Date Tue, 26 Jun 2012 20:56:18 GMT
I found a really good explanation for what I want to do in "Java Servlet Programming", Jason
Hunter et al, chapter 11 "Servlet Collaboration". 
Thanks to all.
Joe

-----Original Message-----
From: Cotton, Joseph B [mailto:bcotton@dpscs.state.md.us] 
Sent: Tuesday, June 26, 2012 2:14 PM
To: Tomcat Users List
Subject: RE: Wish to use an independent class module in Tomcat

Thanks, Konstantine, Cris and Mark.  I will be reading the docs.  
"... global objects should not retain references to objects loaded by your web application..."
 We intend on only doing it the opposite direction, that is, loading global objects into web
apps.  That is the whole point, we want some global objects to live on, after the web app
is gone. 
"... allow each app to have one open..." - yes, and we have a load balancer/round robbin method
of assigning one connection to one session.  It is very fast, obtain connection (which is
already alive), query, get result set, release connection (back to the pool).  
Thanks for the pointers, I will be checking the class loader docs.  So far, I have used class
loader for database connections.  
Thanks
joe

-----Original Message-----
From: Konstantin Kolinko [mailto:knst.kolinko@gmail.com]
Sent: Tuesday, June 26, 2012 12:16 PM
To: Tomcat Users List
Subject: Re: Wish to use an independent class module in Tomcat

2012/6/26 Cotton, Joseph B <bcotton@dpscs.state.md.us>:
> My question may be covered by the Tomcat documentation and I am just 
> confused by all the new terminology.  I have spent hours in reading 
> and still I am looking to an answer.
>
> We wish to have a class running on Tomcat that contains system wide 
> info and multiple database connections into DB2 on the mainframe.
> All other apps runing on Tomcat will open an instance of this class to 
> access the static info and one of five open connections.  Opening and 
> closing database connections is very slow and we wish to leave open 
> the connections and just reuse them as needed.
>
> We wrote the class and it runs ok.  Yet to get it to run with an app, 
> we need to load the class jar file into the app and references in 
> context.xml and web.xml as listed in the documentation. But that 
> defeats the purpose of the global app because then there are multiple 
> instances of the class.
>
> We tried to insert a reference in <GlobalNamingResources> of server.xml.
> It doesn't seem to work for us.
>
> Or are we off base with this design?  Is app to app communication 
> allowed?  Can I call a class from one app to another without first 
> loading the called class into the calling class?
>
>(...)

The first thing you need to consider in your scenario is behaviour of classloaders.
This is documented here:

http://tomcat.apache.org/tomcat-7.0-doc/class-loader-howto.html

One caveat is that, for the reasons documented there, when you put some class into the Common
classloader,  you must remove it from your webapp.

Other caveat is that such global objects should not retain references to objects loaded by
your web application or to its classloader (which is Thread.getContextClassloader() aka TCCL).
 The lifecycle of a webapplication is shorter than the one of Tomcat. A failure to prevent
such references will prevent proper garbage collection of web application classes when the
application is stopped.


As for GlobalNamingResources,  there are several ways to pass a reference to a global object
into the web application.  Using JNDI (via GlobalNamingResources or directly) is one of them.

Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
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


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message