Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem of Druid register mbean error in database

2025-03-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to solve the Druid register mbean error problem of the database". The content of the explanation in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to solve the database Druid register mbean error problem".

Key: [com.alibaba.druid.stat.DruidDataSourceStatManager.addDataSource (DruidDataSourceStatManager.java:154)] register mbean error

When using the database connection pool (this article is common to other applications that use jmx mbean), the following error occurs after a few days of running

2014-11-18 10 com.alibaba.druid.stat.DruidDataSourceStatManager.addDataSource 31 com.alibaba.druid.stat.DruidDataSourceStatManager.addDataSource 00617 [ERROR] [localhost-startStop-6] [com.alibaba.druid.stat.DruidDataSourceStatManager.addDataSource (DruidDataSourceStatManager.java:154)] register mbean error

Javax.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.DefaultMBeanServerInterceptor.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.druid.pool.DruidDataSource.registerMbean (DruidDataSource.java:1294)

At com.alibaba.druid.pool.DruidDataSource.init (DruidDataSource.java:623)

At com.longdai.data.ConnectionManagerDruid. (ConnectionManagerDruid.java:68)

At com.longdai.data.ConnectionManager.getInstance (ConnectionManager.java:86)

At com.longdai.data.dao.Database. (Database.java:22)

At com.longdai.service.admin.CloseNetWorkService.getNetWorkById (CloseNetWorkService.java:87)

At com.longdai.service.admin.CloseNetWorkService$$FastClassByCGLIB$$bbdb465c.invoke ()

At net.sf.cglib.proxy.MethodProxy.invoke (MethodProxy.java:191)

At org.springframework.aop.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 ()

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.apache.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 (FutureTask.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)

Check the source code and trace it 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

Trace the source code all the way. The parameter passed in is always the name attribute. Check the upper DruidDataSourceStatManager.java addDataSource (Object dataSource, String name).

Looking at the upper layer: DruidDataSource.java line:1298

The name property of the data source is passed in here. After the above analysis, it is spliced into an id using the name attribute of DataSource, and then registers the mbean with the secondary id. However, the name attribute of druid is written as a default value.

Therefore, registration failed.

Now we know why this error occurred only after a few days of operation, and the operation and maintenance staff said that it had been rolled back to the previous version and reported this error directly when deploying (redeploying directly, not restarting tomcat/jvm). It was inferred that there was already a mbean of this id in jvm, so even if the redeployment still failed, I thought of a way to restart tomcat and got it, and it worked.

In the wiki of druid, although the configuration name attribute is prompted, it does not work after configuration in the configuration file. After looking at the source code, it is found that the secondary attribute is not loaded, so the configuration is useless. Later, I got the name property of the configuration file in the code, and then dataSource.setName (name). Although the name is set successfully, the custom name can also be seen on the monitoring page of druid. Unfortunately, druid went wrong or redeployed for a few days, and then re-registered mbean with jvm, resulting in an error.

Let's take a look at how the default value of datasource's name is set. DruidAbstractDataSource.java line: 849

You can see that it is DataSource- plus a calculated hash value in the getName property, but this method only returns when getName, while druid's name defaults to null when registering mbean, and parses the following code DruidDataSourceStatManager.java line when registering mbean:

The code shows that I have a hash value calculated according to dataSource, and then register mbean.

After the above analysis, when registering mbean, we must ensure that the name parameter of registerMBean is unique, and we must intercept exceptions in the upper layer.

InstanceAlreadyExistsException, and then automatically handle exceptions

Thank you for your reading, the above is the content of "how to solve the Druid register mbean error problem of the database". After the study of this article, I believe you have a deeper understanding of how to solve the problem of database Druid register mbean error, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report