commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chengkun Li (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (DBCP-533) tomcat register MBean of BasicDataSource with jmxName , appear InstanceAlreadyExistsException
Date Fri, 21 Dec 2018 05:56:00 GMT

     [ https://issues.apache.org/jira/browse/DBCP-533?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Chengkun Li updated DBCP-533:
-----------------------------
    Description: 
We use DBCP2 as GlobalNamingResources in tomcat and I need monitoring  connection of DBCP2
,but does not find how to use JMX in  [http://commons.apache.org/proper/commons-dbcp/configuration.html]

through reading the source code ,i find jmxName properties in 

BasicDataSourceFactory ,when I add the setting like 

jmxName="org.apache.dbcp:DataSource=mydb" in server.xml , there is javax.management.InstanceAlreadyExistsException:
org.apache.dbcp:DataSource=mysqldb when I start up tomcat.

after I debug the code , i find that DBCP have registered the Mbean in BasicDataSource with
jmxName (BasicDataSource line 2390).
{code:java}
// code placeholder
private void jmxRegister() {
    // Return immediately if no JMX name has been specified
    final String requestedName = getJmxName();
    if (requestedName == null) {
        return;
    }
    try {
        ObjectNameWrapper.wrap(requestedName).registerMBean(this);
    } catch (final MalformedObjectNameException e) {
        log.warn("The requested JMX name [" + requestedName + "] was not valid and will be
ignored.");
    }
}
{code}
 

but tomcat will  register the Component in the startup lifecycle , tomcat will use the BasicDataSource's
preRegister method to get the same Mbean name, because BasicDataSource  implements MBeanRegistration.
{code:java}
// code placeholder
if (("javax.sql.DataSource".equals(ref.getClassName())  ||
    "javax.sql.XADataSource".equals(ref.getClassName())) &&
        resource.getSingleton()) {
    try {
        ObjectName on = createObjectName(resource);
        Object actualResource = envCtx.lookup(resource.getName());
        Registry.getRegistry(null, null).registerComponent(actualResource, on, null);
        objectNames.put(resource.getName(), on);
    } catch (Exception e) {
        log.warn(sm.getString("naming.jmxRegistrationFailed", e));
    }
}
{code}
DBCP will register the MBean first ,but when tomcat register it will throw the Exp

BUT i'm not certain that it's a bug or I use it wrong

  was:
We use DBCP2 as GlobalNamingResources in tomcat and I need monitoring  connection of DBCP2
,but does not find how to use JMX in  [http://commons.apache.org/proper/commons-dbcp/configuration.html]

through reading the source code ,i find jmxName properties in 

BasicDataSourceFactory ,when I add the setting like 

jmxName="org.apache.dbcp:DataSource=mydb" in server.xml , there is javax.management.InstanceAlreadyExistsException:
org.apache.dbcp:DataSource=mysqldb when I start up tomcat.

after I debug the code , i find that DBCP have registered the Mbean in BasicDataSource with
jmxName (BasicDataSource line 2390).
{code:java}
// code placeholder
private void jmxRegister() {
    // Return immediately if no JMX name has been specified
    final String requestedName = getJmxName();
    if (requestedName == null) {
        return;
    }
    try {
        ObjectNameWrapper.wrap(requestedName).registerMBean(this);
    } catch (final MalformedObjectNameException e) {
        log.warn("The requested JMX name [" + requestedName + "] was not valid and will be
ignored.");
    }
}
{code}
 

but tomcat will  register the Component in the startup lifecycle , tomcat will use the BasicDataSource's
preRegister method to get the same Mbean name, because BasicDataSource  implements MBeanRegistration.
{code:java}
// code placeholder
if (("javax.sql.DataSource".equals(ref.getClassName())  ||
    "javax.sql.XADataSource".equals(ref.getClassName())) &&
        resource.getSingleton()) {
    try {
        ObjectName on = createObjectName(resource);
        Object actualResource = envCtx.lookup(resource.getName());
        Registry.getRegistry(null, null).registerComponent(actualResource, on, null);
        objectNames.put(resource.getName(), on);
    } catch (Exception e) {
        log.warn(sm.getString("naming.jmxRegistrationFailed", e));
    }
}
{code}
so when 

BUT i'm not certain that it's a bug or I use it wrong


> tomcat register MBean of BasicDataSource with jmxName , appear InstanceAlreadyExistsException
> ---------------------------------------------------------------------------------------------
>
>                 Key: DBCP-533
>                 URL: https://issues.apache.org/jira/browse/DBCP-533
>             Project: Commons DBCP
>          Issue Type: Bug
>    Affects Versions: 2.0
>         Environment: tomcat 8.5.32 
>            Reporter: Chengkun Li
>            Priority: Major
>              Labels: InstanceAlreadyExistsException, jmxName
>         Attachments: 20181221101406115.png, 20181221101456927.png
>
>
> We use DBCP2 as GlobalNamingResources in tomcat and I need monitoring  connection of
DBCP2 ,but does not find how to use JMX in  [http://commons.apache.org/proper/commons-dbcp/configuration.html]
> through reading the source code ,i find jmxName properties in 
> BasicDataSourceFactory ,when I add the setting like 
> jmxName="org.apache.dbcp:DataSource=mydb" in server.xml , there is javax.management.InstanceAlreadyExistsException:
org.apache.dbcp:DataSource=mysqldb when I start up tomcat.
> after I debug the code , i find that DBCP have registered the Mbean in BasicDataSource
with jmxName (BasicDataSource line 2390).
> {code:java}
> // code placeholder
> private void jmxRegister() {
>     // Return immediately if no JMX name has been specified
>     final String requestedName = getJmxName();
>     if (requestedName == null) {
>         return;
>     }
>     try {
>         ObjectNameWrapper.wrap(requestedName).registerMBean(this);
>     } catch (final MalformedObjectNameException e) {
>         log.warn("The requested JMX name [" + requestedName + "] was not valid and will
be ignored.");
>     }
> }
> {code}
>  
> but tomcat will  register the Component in the startup lifecycle , tomcat will use
the BasicDataSource's preRegister method to get the same Mbean name, because BasicDataSource 
implements MBeanRegistration.
> {code:java}
> // code placeholder
> if (("javax.sql.DataSource".equals(ref.getClassName())  ||
>     "javax.sql.XADataSource".equals(ref.getClassName())) &&
>         resource.getSingleton()) {
>     try {
>         ObjectName on = createObjectName(resource);
>         Object actualResource = envCtx.lookup(resource.getName());
>         Registry.getRegistry(null, null).registerComponent(actualResource, on, null);
>         objectNames.put(resource.getName(), on);
>     } catch (Exception e) {
>         log.warn(sm.getString("naming.jmxRegistrationFailed", e));
>     }
> }
> {code}
> DBCP will register the MBean first ,but when tomcat register it will throw the Exp
> BUT i'm not certain that it's a bug or I use it wrong



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message