|Summary:||Error in the JNDI Generic JavaBean Resources documentation|
|Product:||Tomcat 7||Reporter:||Giulio Quaresima <giulio.quaresima>|
|Component:||Documentation||Assignee:||Tomcat Developers Mailing List <dev>|
|Attachments:||server.xml and the test classes in maven format|
Description Giulio Quaresima 2013-10-25 11:50:00 UTC
http://tomcat.apache.org/tomcat-7.0-doc/jndi-resources-howto.html#Generic_JavaBean_Resources In this page of the Tomcat 7 documentation - but this is true for all versions - there is the following statement: "The resource factory will create a new instance of the appropriate bean class every time a lookup() for this entry is made." But that seems not true. I created an example foo.bar.Bean, which simply increment a static int at each creation. Then, I configured a BeanFactory in the global resources section of server.xml, and I deployed a servlet which simply lookup 1000 thousand times for the bean and print its string representation in the response. To reproduce, follow the steps below using the targz attached: 1) configure a resource with a BeanFactory, as in the server.xml attached; 2) put the bean-factory-bug-bean.jar in the common classpath of the container; 3) start the container; 4) deploy the bean-factory-bug-web.war file in the appbase folder; 5) open http://localhost:8080/bean-factory-bug-web/BeanServlet As for one can read from the documentation, the expected output is Bean #1 Bean #2 Bean #3 ... Bean #999 Bean #1000 But the actual output is Bean #1 Bean #1 Bean #1 ... Bean #1 Bean #1 I think that the actual behaviour of the container is the most advisable behaviour, but would be better to update the documentation to match it and avoid misleading. Thanks. Giulio Quaresima (Ph.D) - Perugia - Italy
Comment 1 Giulio Quaresima 2013-10-25 11:51:33 UTC
Created attachment 30969 [details] server.xml and the test classes in maven format
Comment 2 Mark Thomas 2013-10-29 14:14:56 UTC
This behavior is controlled by the singleton attribute of the factory. The default is to create singleton resources as that is what users expect even though the J2EE spec suggests that a new object should be created on each lookup. I'll go through the JNDI docs and expand any statements like the one you quote below so that the full picture is available.
Comment 3 Giulio Quaresima 2013-10-29 14:32:05 UTC
OK, this is true for Tomcat 7 but it's not, as I can see, for the still supported 6.x version. Moreover, I think it would be better to mention the 'singleton' option also in the documentation page I refer to, in order do avoid misunderstanding. Thanks (In reply to Mark Thomas from comment #2) > This behavior is controlled by the singleton attribute of the factory. The > default is to create singleton resources as that is what users expect even > though the J2EE spec suggests that a new object should be created on each > lookup. > > I'll go through the JNDI docs and expand any statements like the one you > quote below so that the full picture is available.
Comment 4 Mark Thomas 2013-10-29 14:36:17 UTC
JNDI how-to updated in 7.0.x for 7.0.48 onwards and 8.0.x for 8.0.0-RC6 onwards.