Commons Dbcp
  1. Commons Dbcp
  2. DBCP-411

BasicManagedDataSource - unregister from JMX on close()

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0
    • Fix Version/s: 2.0
    • Labels:
      None

      Description

      There is a JMX registration issue in TestBasicManagedDataSource.

      If the test is run with logging:

      mvn test -Dtest=TestBasicManagedDataSource -Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog

      then lots of stack traces are shown as below.

      This appears to be because each name can only be registered once.

      Perhaps the test is flawed, and it should deregister the name in tearDown() ?
      However there does not seem to be a way to deregister the name.

      [WARN] BasicDataSource - Failed to complete JMX registration <javax.management.InstanceAlreadyExistsException: org.apache.commons.dbcp2:name=test>javax.management.InstanceAlreadyExistsException: org.apache.commons.dbcp2:name=test
              at com.sun.jmx.mbeanserver.Repository.addMBean(Repository.java:437)
              at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerWithRepository(DefaultMBeanServerInterceptor.java:1898)
              at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerDynamicMBean(DefaultMBeanServerInterceptor.java:966)
              at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerObject(DefaultMBeanServerInterceptor.java:900)
              at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(DefaultMBeanServerInterceptor.java:324)
              at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.java:522)
              at org.apache.commons.dbcp2.BasicDataSource.jmxRegister(BasicDataSource.java:2224)
              at org.apache.commons.dbcp2.BasicDataSource.createDataSource(BasicDataSource.java:1909)
              at org.apache.commons.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:1433)
              at org.apache.commons.dbcp2.TestBasicDataSource.getConnection(TestBasicDataSource.java:48)
              at org.apache.commons.dbcp2.TestConnectionPool.testHashing(TestConnectionPool.java:530)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
              at java.lang.reflect.Method.invoke(Method.java:606)
              at junit.framework.TestCase.runTest(TestCase.java:176)
              at junit.framework.TestCase.runBare(TestCase.java:141)
              at junit.framework.TestResult$1.protect(TestResult.java:122)
              at junit.framework.TestResult.runProtected(TestResult.java:142)
              at junit.framework.TestResult.run(TestResult.java:125)
              at junit.framework.TestCase.run(TestCase.java:129)
              at junit.framework.TestSuite.runTest(TestSuite.java:255)
              at junit.framework.TestSuite.run(TestSuite.java:250)
              at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:84)
              at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:264)
              at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153)
              at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:124)
              at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:200)
              at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:153)
              at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
      

        Activity

        Hide
        Sebb added a comment -

        Adding the following code to the close() method seems to avoid the problem

        if (registeredJmxName != null) {
            MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
            try {
                mbs.unregisterMBean(registeredJmxName);
            } catch (JMException e) {
                log.warn("Failed to unregister the JMX name: " + registeredJmxName, e);
            } finally {
                registeredJmxName = null;
            }
        }
        

        Does that make sense to apply?

        Show
        Sebb added a comment - Adding the following code to the close() method seems to avoid the problem if (registeredJmxName != null ) { MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); try { mbs.unregisterMBean(registeredJmxName); } catch (JMException e) { log.warn( "Failed to unregister the JMX name: " + registeredJmxName, e); } finally { registeredJmxName = null ; } } Does that make sense to apply?
        Hide
        Mark Thomas added a comment -

        Looks good to me.

        Show
        Mark Thomas added a comment - Looks good to me.
        Hide
        Sebb added a comment -

        URL: http://svn.apache.org/r1572118
        Log:
        DBCP-411 BasicManagedDataSource - unregister from JMX on close()

        Modified:
        commons/proper/dbcp/trunk/src/changes/changes.xml
        commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java

        Show
        Sebb added a comment - URL: http://svn.apache.org/r1572118 Log: DBCP-411 BasicManagedDataSource - unregister from JMX on close() Modified: commons/proper/dbcp/trunk/src/changes/changes.xml commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java

          People

          • Assignee:
            Unassigned
            Reporter:
            Sebb
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development