You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Michael Echerer <me...@tngtech.com> on 2005/04/12 17:37:50 UTC

Custom JNDI resource and Tomcat BeanFactory seem to always return the same object instance


Hi,

I was testing the JNDI Resource configuration using a custom resource factory
and/or the Tomcat BeanFactory following the tutorial here with Tomcat 5.0.28:
http://jakarta.apache.org/tomcat/tomcat-5.0-doc/jndi-resources-howto.html

For Generic Java Bean resources the documentation says:

"The resource factory will create a new instance of the appropriate bean class
every time a lookup() for this entry is made."

Same is said for a custom resource factory. But actually this is not true... :-(

When I tried the demo classes with the MyBean and MyBeanFactory i found out that
"always" the same MyBean instance is returned when calling lookup(). It doesn't
matter whether I use the Tomcat BeanFactory or the mentioned custom
MyBeanFactory.

I would say this is because the method getObjectInstance(Object obj,Name name,
Context nameCtx, Hashtable environment) is not called multiple times (each
lookup() ), but really only once! I can say this because I added a log
statement into this method of MyBeanFactory. Only appears once, so it doesn't
help to issue "new MyBean()" as the first bean ever created seems to be
remembered somehow.

When I configured the MyBeanFactory in server.xml as GlobalResource instead of
the context I could see that the getObjectInstance method is already called
upon Tomcat startup when no web application ever called InitialContext.lookup()
and wasn't even deployed.


My question: Is it simply documented wrongly that each lookup() would return a
new object, is there any chance for a config problem or is this a bug?

I'd like to implement a custom resource factory that has a "pool" behind. Hence
it makes a huge difference whether I "always" get the same object (that would
mean that the object returned needs to be the pool itself and the app can grab
the pooled objects) or if there's a chance to have any pooled object from the
pool returned each time lookup() is called.

Any ideas upon this?

Cheers,
Michael

P.S. BTW the documentation examples should be reviewed as there are a few typos
and some configuration statements that didn't work at all...




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