[Com.alibaba.druid.stat.DruidDataSourceStatManager.addDataSource (druiddatasourcestatmanager.java:154

Source: Internet
Author: User
Tags addchild custom name

Key: [Com.alibaba.druid.stat.DruidDataSourceStatManager.addDataSource (druiddatasourcestatmanager.java:154)] Register Mbean Error

When using a database connection pool (This article is common to other apps that use JMX Mbean), the following error occurs after several days of running

2014/11/18 10:31:00,617 [ERROR] [localhost-startstop-6] [ Com.alibaba.druid.stat.DruidDataSourceStatManager.addDataSource (druiddatasourcestatmanager.java:154)] Register Mbean Errorjavax.management.instancealreadyexistsexception:com.alibaba.druid:type=druiddatasource,id=druid MySQL DB pool at Com.sun.jmx.mbeanserver.Repository.addMBean (repository.java:453) at Com.sun.jmx.interceptor.Defau Ltmbeanserverinterceptor.internal_addobject (defaultmbeanserverinterceptor.java:1484) at Com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerDynamicMBean (Defaultmbeanserverinterceptor.java : 963) at Com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerObject (Defaultmbeanserverinterceptor.java : 917) at Com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean (Defaultmbeanserverinterceptor.java : 312) at Com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean (jmxmbeanserver.java:482) at Com.alibaba.druid. Stat. Druiddatasourcestatmanager.AddDatasource (druiddatasourcestatmanager.java:152) at Com.alibaba.druid.pool.druiddatasource$1.run ( druiddatasource.java:1298) at java.security.AccessController.doPrivileged (Native Method) at Com.alibaba.drui D.pool.druiddatasource.registermbean (druiddatasource.java:1294) at Com.alibaba.druid.pool.DruidDataSource.init ( druiddatasource.java:623) at com.longdai.data.connectionmanagerdruid.<init> (ConnectionManagerDruid.java:68 ) at Com.longdai.data.ConnectionManager.getInstance (connectionmanager.java:86) at Com.longdai.data.dao.Datab Ase.<clinit> (database.java:22) at Com.longdai.service.admin.CloseNetWorkService.getNetWorkById ( closenetworkservice.java:87) at com.longdai.service.admin.closenetworkservice$ $FastClassByCGLIB $ $bbdb 465c.invoke (<generated>) at Net.sf.cglib.proxy.MethodProxy.invoke (methodproxy.java:191) at Org.springframework.ao P.framework.cglib2aopproxy$cglibmethodinvocation.invokejoinpoint(cglib2aopproxy.java:700) at Org.springframework.aop.framework.ReflectiveMethodInvocation.proceed ( reflectivemethodinvocation.java:149) at Com.gozap.services.ServiceMethodInterceptor.invoke ( servicemethodinterceptor.java:31) at Org.springframework.aop.framework.ReflectiveMethodInvocation.proceed ( reflectivemethodinvocation.java:171) at Org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke ( exposeinvocationinterceptor.java:89) at Org.springframework.aop.framework.ReflectiveMethodInvocation.proceed ( reflectivemethodinvocation.java:171) at org.springframework.aop.framework.cglib2aopproxy$ Dynamicadvisedinterceptor.intercept (cglib2aopproxy.java:635) at com.longdai.service.admin.closenetworkservice$$ Enhancerbycglib$$19cbebaf.getnetworkbyid (<generated>) at Com.longdai.system.listener.CloseNetWorkConfigiListener.contextInitialized (closenetworkconfigilistener.java:37 ) at Org.apache.catalina.core.StandardContext.lisTenerstart (standardcontext.java:4791) at Org.apache.catalina.core.StandardContext.startInternal ( standardcontext.java:5285) at Org.apache.catalina.util.LifecycleBase.start (lifecyclebase.java:150) at Org.ap Ache.catalina.core.ContainerBase.addChildInternal (containerbase.java:901) at Org.apache.catalina.core.ContainerBase.addChild (containerbase.java:877) at Org.apache.catalina.core.StandardHost.addChild (standardhost.java:618) at Org.apache.catalina.startup.HostConfig.deployWAR (hostconfig.java:963) at org.apache.catalina.startup.hostconfig$        Deploywar.run (hostconfig.java:1600) at Java.util.concurrent.executors$runnableadapter.call (Executors.java:441) At Java.util.concurrent.futuretask$sync.innerrun (futuretask.java:303) at Java.util.concurrent.FutureTask.run (Fut uretask.java:138) at Java.util.concurrent.threadpoolexecutor$worker.runtask (threadpoolexecutor.java:886) at Java.util.concurrent.threadpoolexecutor$workEr.run (threadpoolexecutor.java:908) at Java.lang.Thread.run (thread.java:619) 
View the source code, always follow up to

At Com.sun.jmx.mbeanserver.Repository.addMBean (repository.java:453) at        Com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.internal_addObject (Defaultmbeanserverinterceptor.java : 1484)//Here at        Com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerDynamicMBean ( defaultmbeanserverinterceptor.java:963) at        Com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerObject (defaultmbeanserverinterceptor.java:917) At        Com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean (Defaultmbeanserverinterceptor.java : 312)//here Entrance

All the way to follow the source, the passed parameter has been the Name property, view the upper Druiddatasourcestatmanager.java AddDatasource (Object dataSource, String name)

Looking at the upper deck: Druiddatasource.java line:1298


Here the Name property of the data source is passed in, and the above analysis is to use the name attribute of DataSource to stitch into an ID, then register the Mbean with the secondary ID, however, the Name property of Druid is written as a default value


Therefore, registration failed.


Now that we know why, why this error occurred several days later, and OPS said it was rolled back to the previous version, when the deployment (direct redeployment, and did not restart TOMCAT/JVM) to report this error directly, after the inference is that the JVM already has an mbean of this ID, So even if the redeployment or failure, I have to think of a way to restart Tomcat, done, it really worked.

In Druid Wiki, although prompted to configure the Name property, but configured in the configuration file does not work, after viewing the source code discovery did not load the secondary attribute, so the configuration is useless, and later I get the Name property of the configuration file in the code, Then Datasource.setname (name), although the name is set successfully, in the Druid monitoring page can also look at the custom name, but unfortunately Druid run a few days error or redeploy, and then re-register the Mbean to the JVM, resulting in an error.

Let's see how the default value of DataSource's name is set Druidabstractdatasource.java line:849


You can see that in the GetName attribute is a hash value of datasource-plus calculation, but this method only returns at GetName, and the name of Druid when registering an mbean is null by default. Analyze the following code when registering an Mbean Druiddatasourcestatmanager.java line:161


Code display is calculated based on DataSource a hash value, and then register the Mbean.


After the above analysis in registering the Mbean, be sure to ensure that the Registermbean name parameter is unique, but also to intercept the exception on the upper level

Instancealreadyexistsexception, and then automatically handles exceptions

When using Druid, do not use the name attribute, Druid official website does not give a description, this article here to give you an explanation and processing method.

Attached: https://github.com/alibaba/druid


[Com.alibaba.druid.stat.DruidDataSourceStatManager.addDataSource (druiddatasourcestatmanager.java:154

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.