3

我将 app1.war 和 app2.war 部署在同一个 tomcat jvm 中。两个应用程序都有自己的上下文 xml - app1.xml 和 app2.xml。这两个应用程序都包含连接到 Cassandra 的 datastax 驱动程序依赖项。它们在单独部署时运行良好。但是当两者都部署在同一个 jvm 中时,我在日志中看到以下 JMX 异常:

[DEBUG] [TokenId=] [2015-07-29 20:54:35.177] [DefaultListableBeanFactory] - [Eagerly caching bean 'cluster' to allow for resolving potential circular references]
[DEBUG] [TokenId=] [2015-07-29 20:54:35.191] [DefaultListableBeanFactory] - [Invoking afterPropertiesSet() on bean with name 'cluster']
[DEBUG] [TokenId=] [2015-07-29 20:54:35.199] [SystemProperties] - [com.datastax.driver.NEW_NODE_DELAY_SECONDS is undefined, using default value 1]
[DEBUG] [TokenId=] [2015-07-29 20:54:35.199] [SystemProperties] - [com.datastax.driver.NON_BLOCKING_EXECUTOR_SIZE is undefined, using default value 16]
[DEBUG] [TokenId=] [2015-07-29 20:54:35.205] [SystemProperties] - [com.datastax.driver.NOTIF_LOCK_TIMEOUT_SECONDS is undefined, using default value 60]
[WARN ] [TokenId=] [2015-07-29 20:54:35.217] [FrameCompressor] - [Cannot find Snappy class, you should make sure the Snappy library is in the classpath if you intend to use it. Snappy compression
will not be available for the protocol.]
[WARN ] [TokenId=] [2015-07-29 20:54:35.219] [FrameCompressor] - [Cannot find LZ4 class, you should make sure the LZ4 library is in the classpath if you intend to use it. LZ4 compression will not
be available for the protocol.]
[DEBUG] [TokenId=] [2015-07-29 20:54:35.356] [Cluster] - [Starting new cluster with contact points [xxxxx1.com/10.63.162.182:9042, xxxx2.com/10.63.162.177:9042, xxxx3.com/10.63.162.183:9042]]
[DEBUG] [TokenId=] [2015-07-29 20:54:35.556] [JmxReporter] - [Unable to register gauge]
javax.management.InstanceAlreadyExistsException: cluster1-metrics:name=open-connections
        at com.sun.jmx.mbeanserver.Repository.addMBean(Unknown Source) ~[?:1.7.0_45]
        at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerWithRepository(Unknown Source) ~[?:1.7.0_45]
        at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerDynamicMBean(Unknown Source) ~[?:1.7.0_45]
        at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerObject(Unknown Source) ~[?:1.7.0_45]
        at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(Unknown Source) ~[?:1.7.0_45]
        at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(Unknown Source) ~[?:1.7.0_45]
        at com.codahale.metrics.JmxReporter$JmxListener.onGaugeAdded(JmxReporter.java:494) [metrics-core-3.0.2.jar:3.0.2]
        at com.codahale.metrics.MetricRegistry.notifyListenerOfAddedMetric(MetricRegistry.java:344) [metrics-core-3.0.2.jar:3.0.2]
        at com.codahale.metrics.MetricRegistry.addListener(MetricRegistry.java:187) [metrics-core-3.0.2.jar:3.0.2]
        at com.codahale.metrics.JmxReporter.start(JmxReporter.java:697) [metrics-core-3.0.2.jar:3.0.2]
        at com.datastax.driver.core.Metrics.<init>(Metrics.java:77) [cassandra-driver-core-2.1.4.jar:?]
        at com.datastax.driver.core.Cluster$Manager.<init>(Cluster.java:1204) [cassandra-driver-core-2.1.4.jar:?]
        at com.datastax.driver.core.Cluster$Manager.<init>(Cluster.java:1144) [cassandra-driver-core-2.1.4.jar:?]
        at com.datastax.driver.core.Cluster.<init>(Cluster.java:121) [cassandra-driver-core-2.1.4.jar:?]
        at com.datastax.driver.core.Cluster.<init>(Cluster.java:108) [cassandra-driver-core-2.1.4.jar:?]
        at com.datastax.driver.core.Cluster.buildFrom(Cluster.java:177) [cassandra-driver-core-2.1.4.jar:?]
        at com.datastax.driver.core.Cluster$Builder.build(Cluster.java:1109) [cassandra-driver-core-2.1.4.jar:?]

该应用程序可以正常工作。我只是担心为什么会看到此错误以及如何避免此错误。

4

1 回答 1

8

正如您所指出的,除了不注册集群的指标 MBean 之一之外,这不会导致任何问题。为防止出现此消息/问题,您可以为集群实例指定唯一名称,可能与应用程序本身的名称相关联。

    Cluster cluster = Cluster.builder().withClusterName("myapplication")
            .build();

这将为您的 mbean 名称添加前缀“myapplication-1”。

否则,您可以使用withoutJMXReportingwithoutMetrics一起禁用 JMX 指标来禁用指标报告。

于 2015-07-29T21:45:47.630 回答