This week's book giveaway is in the Beginning Java forum.
We're giving away four copies of Get Programming with Java (MEAP only) and have Peggy Fisher on-line!
See this thread for details.
Win a copy of Get Programming with Java (MEAP only) this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

Tomcat resources in application context  RSS feed

Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,
This is my first post here. Not sure if it belongs to the servlets or the tomcat subforum.

Some background first -
I am using a database pooling framework called primrose. Among other things, it contains a web console, using which one may view the statuses and statistics about database connections. The console works as follows - an ObjectFactory implementor is provided, and the webconsole needs to be declared as a resource. The factory starts a (non daemon) thread in the background, and starts listening for connections on some port. To shut down the web console, a servlet class in the Primrose code needs to be declared in web.xml, and this servlet shuts down the web console, among other things.

Some questions:
1. AFAIK, the resource can be declared in the application's context, as well as in the GlobalResources context. The rest of the framework uses configuration (such as db connection info) can be declared in the application's context. Can something declared as a resource in the global context access a class created by a resource declaration in an application context? I did not think that it was possible, but that is how it seems to be - I verified it using a debugger.

2. As I mentioned above, the resource creates a thread in the background. When is the resource loaded - i.e. when is the factory method of the resource called? Based on my observations (using debuggers, etc), if the resource is declared in the global context, it is loaded when tomcat starts. If it is declared in the application context, the factory method is not called unless
a) It is called when a lookup is performed in the code, mentioned here -
Something like:

b) It is of type javax.sql.DataSource. This may sound strange, but here's the relevant code listing from the addResource method of org.apache.catalina.core.NamingContextListener class

As mentioned before, the webconsole needs to get the getinstance() method of its factory called. This can be done by putting it in the global context, but how does one do it by putting it in the META-INF/context.xml? Declaring the resource's type as javax.sql.DataSource may do the trick, but sounds like a real hack. Any suggestions?
"I know this defies the law of gravity... but I never studied law." -B. Bunny Defiant tiny ad:
Programmatically Create PDF Using Free Spire.PDF with Java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!