Hi!

I am using Tomcat 7.0.29 with a custom JNDI resource factory
(http://tomcat.apache.org/tomcat-7.0-doc/jndi-resources-howto.html#Adding_Custom_Resource_Factories).
The factory creates a connection to data server which then can be
shared between servlets.
Two questions regarding the resource usage.

1. Creation of the resource factory, isn't is supposed to be thread-safe?
The resource (connection) is used by two servlets which obtains it on
start-up. It works fine if the servlets are loaded one after another -
the first servlet asks JNDI for a connection, JNDI creates a factory,
the factory creates a connection, JNDI gives the connection to the
servlet; the second one ask JNDI for a connection and immediately gets
the same connection, without calling the factory. But if the servlets
are being started exactly at the same time, they get two different
connections created by two different factories. Shouldn't the factory
singleton-ness be managed by Tomcat?

2. What is the correct way to close the resource?
How should I close the resource if the webapp is being
stopped/undeployed? My factory creates a connection on "please create
a resource" call somewhere from inside JNDI, lets the connection go
and doesn't know how many servlets use it. Users of the resource are
independent, they do not know how many of them are and do not know
when the resource can be closed. So I would expect some kind of "it's
time to close the resource(s)" call from JNDI. Is there one?
I know that I can track all the resources creation in a
ServletContextListener and then close them in contextDestroyed(), but
I hope there is a nicer way.


Thanks in advance,
Kirill

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

Reply via email to