Project: Tomcat
Bug 53416 Two datasources with the same name in different web applications results in javax.management.InstanceAlreadyExistsException
Reported: 2012-06-14 13:37:06 | Status: resolved fixed

Deploy two different web applications onto Tomcat. Each web application has a resource that: * uses the Use Tomcat JDBC Connection Pool * has an identical name to the other one <Resource name="jdbc/collision" factory="org.apache.tomcat.jdbc.pool.DataSourceFactory" ... /> When starting the server you get a non fatal error in the logs InstanceAlreadyExistsException. Both applications appear to still work OK ERROR org.apache.tomcat.jdbc.pool.DataSource - Unable to register JDBC pool with JMX javax.management.InstanceAlreadyExistsException: tomcat.jdbc:name="jdbc/soscvuk",context=/,type=ConnectionPool,host=localhost,class=org.apache.tomcat.jdbc.pool. DataSource at com.sun.jmx.mbeanserver.Repository.addMBean(Repository.java:453) ~[na:1.6.0_32] at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.internal_addObject(DefaultMBeanServerInterceptor.java:1484) [na:1.6.0_32] at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerDynamicMBean(DefaultMBeanServerInterceptor.java:963) [na:1.6.0_32] at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerObject(DefaultMBeanServerInterceptor.java:917) [na:1.6.0_32] at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(DefaultMBeanServerInterceptor.java:312) [na:1.6.0_32] at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.java:482) [na:1.6.0_32] at org.apache.tomcat.jdbc.pool.DataSource.registerJmx(DataSource.java:135) [tomcat-jdbc.jar:na] at org.apache.tomcat.jdbc.pool.DataSource.preRegister(DataSource.java:102) [tomcat-jdbc.jar:na] at org.apache.tomcat.util.modeler.BaseModelMBean.preRegister(BaseModelMBean.java:1132) [tomcat-coyote.jar:7.0.27] at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.preRegisterInvoke(DefaultMBeanServerInterceptor.java:1010) [na:1.6.0_32] at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerDynamicMBean(DefaultMBeanServerInterceptor.java:938) [na:1.6.0_32] at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerObject(DefaultMBeanServerInterceptor.java:917) [na:1.6.0_32] at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(DefaultMBeanServerInterceptor.java:312) [na:1.6.0_32] at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.java:482) [na:1.6.0_32] at org.apache.tomcat.util.modeler.Registry.registerComponent(Registry.java:742) [tomcat-coyote.jar:7.0.27] at org.apache.catalina.core.NamingContextListener.addResource(NamingContextListener.java:1062) [catalina.jar:7.0.27] at org.apache.catalina.core.NamingContextListener.createNamingContext(NamingContextListener.java:671) [catalina.jar:7.0.27] at org.apache.catalina.core.NamingContextListener.lifecycleEvent(NamingContextListener.java:270) [catalina.jar:7.0.27] at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119) [catalina.jar:7.0.27] at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90) [catalina.jar:7.0.27] at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5161) [catalina.jar:7.0.27] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [catalina.jar:7.0.27] at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:895) [catalina.jar:7.0.27] at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:871) [catalina.jar:7.0.27] at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615) [catalina.jar:7.0.27] at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:649) [catalina.jar:7.0.27] at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1585) [catalina.jar:7.0.27] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441) [na:1.6.0_32] at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) [na:1.6.0_32] at java.util.concurrent.FutureTask.run(FutureTask.java:138) [na:1.6.0_32] at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [na:1.6.0_32] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [na:1.6.0_32] at java.lang.Thread.run(Thread.java:662) [na:1.6.0_32]

Files changed in fix:
modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/DataSource.java