MBeanServer server = getContainerWrapper().getResourceResolver().getMBeanServer();
for (Iterator it = executorNames.iterator(); it.hasNext();) {
ObjectName executorName = (ObjectName) it.next();
ThreadPool threadPool = new ThreadPool();
threadPool.setName(executorName.getKeyProperty("name"));
threadPool.setMaxThreads(JmxTools.getIntAttr(server, executorName, "maxThreads"));
threadPool.setMaxSpareThreads(JmxTools.getIntAttr(server, executorName, "largestPoolSize"));
threadPool.setMinSpareThreads(JmxTools.getIntAttr(server, executorName, "minSpareThreads"));
threadPool.setCurrentThreadsBusy(JmxTools.getIntAttr(server, executorName, "activeCount"));
threadPool.setCurrentThreadCount(JmxTools.getIntAttr(server, executorName, "poolSize"));
threadPools.add(threadPool);
}
for (Iterator it = poolNames.iterator(); it.hasNext();) {
ThreadPoolObjectName threadPoolObjectName = (ThreadPoolObjectName) it.next();
try {
ObjectName poolName = threadPoolObjectName.getThreadPoolName();
ThreadPool threadPool = new ThreadPool();
threadPool.setName(poolName.getKeyProperty("name"));
threadPool.setMaxThreads(JmxTools.getIntAttr(server, poolName, "maxThreads"));
if (JmxTools.hasAttribute(server, poolName, "maxSpareThreads")) {
threadPool.setMaxSpareThreads(JmxTools.getIntAttr(server, poolName, "maxSpareThreads"));
threadPool.setMinSpareThreads(JmxTools.getIntAttr(server, poolName, "minSpareThreads"));
}
threadPool.setCurrentThreadsBusy(JmxTools.getIntAttr(server, poolName, "currentThreadsBusy"));
threadPool.setCurrentThreadCount(JmxTools.getIntAttr(server, poolName, "currentThreadCount"));
// Tomcat 6.0.21+ will return -1 for maxThreads if the connector uses an executor for its threads.
// In this case, don't add its ThreadPool to the results.
if (threadPool.getMaxThreads() > -1) {
threadPools.add(threadPool);
}
} catch (InstanceNotFoundException e) {
logger.error("Failed to query entire thread pool " + threadPoolObjectName);
logger.debug(e);