我尝试检查server.xml中的连接池
这是我来自Tomcat的server.xml
server.xml
<GlobalNamingResources>
<Resource name="jdbc/test" auth="Container"
type="javax.sql.DataSource"
maxTotal="200" maxIdle="50" maxWaitMillis="10000"
username="test" password="test"
driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
url="jdbc:sqlserver://localhost\test;databaseName=test" />
</GlobalNamingResources>
context.xml
<Context>
<ResourceLink name="jdbc/test"
golbal="jdbc/test"
type="javax.sql.DataSource" />
</Context>
我不知道如何从server.xml检查连接池,因为我错误地/或者没有将数据源放在context.xml中。
由于服务器处于生产环境中,因此无法重置。我无法将数据源更改为context.xml
我查阅了很多参考资料,连接池的大部分监视器都是将数据源放在context.xml中
例如:http://www.jcgonzalez.com/java-monitor-jdbc-connection-pool-servlet
我遵循上面的所有代码,可以在Testing Environment中检查连接池。
但我无法从server.xml检查连接池。
server.xml中是否有检查数据源连接池状态的参考编码?
我试过了
try {
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
Set<ObjectName> objectNames = server.queryNames(null, null);
for (ObjectName name : objectNames) {
MBeanInfo info = server.getMBeanInfo(name);
if (info.getClassName().equals(
"org.apache.catalina.mbeans.ContextResourceLinkMBean")) {
for (MBeanAttributeInfo mf : info.getAttributes()) {
Object attributeValue = server.getAttribute(name,
mf.getName());
if (attributeValue != null) {
writer.println("" + mf.getName() + " : "
+ attributeValue.toString() + "<br/>");
}
}
break;
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
但它只返回:
name : jdbc/test
global : jdbc/test
type : javax.sql.DataSource
我想检查连接池状态,而不是context.xml中的引用
有人能帮帮忙吗?
发布于 2018-06-13 16:04:39
此演示文稿可能会帮助您满足监控要求:
Tomcat Presentations -只需搜索“监控”即可。
https://stackoverflow.com/questions/50732947
复制