# This patch file was generated by NetBeans IDE # Following Index: paths are relative to: /Users/oleksiys/Projects/Glassfish/v3/core/kernel/src/main/java/com/sun/enterprise/v3/services/impl/monitor # This patch can be applied using context Tools: Patch action on respective folder. # It uses platform neutral UTF-8 encoding and \n newlines. # Above lines and this line are ignored by the patching process. Index: MonitorableThreadPool.java --- MonitorableThreadPool.java Base (BASE) +++ MonitorableThreadPool.java Locally Modified (Based On LOCAL) @@ -37,6 +37,7 @@ */ package com.sun.enterprise.v3.services.impl.monitor; +import com.sun.enterprise.v3.services.impl.monitor.probes.ThreadPoolProbeProvider; import com.sun.grizzly.http.StatsThreadPool; import java.util.concurrent.ThreadFactory; import java.util.concurrent.TimeUnit; @@ -45,6 +46,7 @@ * Grizzly thread pool implementation that emits probe events. * * @author jluehe + * @author Alexey Stashok */ public class MonitorableThreadPool extends StatsThreadPool { @@ -57,6 +59,14 @@ this.monitoring = monitoring; this.threadPoolMonitoringName = threadPoolMonitoringName; setThreadFactory(new ProbeWorkerThreadFactory()); + + final ThreadPoolProbeProvider threadPoolProbeProvider = + monitoring.getThreadPoolProbeProvider(); + + threadPoolProbeProvider.setCoreThreadsEvent( + threadPoolMonitoringName, corePoolSize); + threadPoolProbeProvider.setMaxThreadsEvent( + threadPoolMonitoringName, maxPoolSize); } public MonitorableThreadPool( @@ -68,9 +78,59 @@ this.monitoring = monitoring; this.threadPoolMonitoringName = threadPoolMonitoringName; setThreadFactory(new ProbeWorkerThreadFactory()); + + final ThreadPoolProbeProvider threadPoolProbeProvider = + monitoring.getThreadPoolProbeProvider(); + + threadPoolProbeProvider.setCoreThreadsEvent( + threadPoolMonitoringName, super.corePoolSize); + threadPoolProbeProvider.setMaxThreadsEvent( + threadPoolMonitoringName, super.maxPoolSize); } @Override + public void setCorePoolSize(int corePoolSize) { + synchronized (statelock) { + super.setCorePoolSize(corePoolSize); + + if (monitoring == null) return; + + monitoring.getThreadPoolProbeProvider().setCoreThreadsEvent( + threadPoolMonitoringName, corePoolSize); + } + } + + @Override + public void setMaximumPoolSize(int maxPoolSize) { + synchronized (statelock) { + super.setMaximumPoolSize(maxPoolSize); + + if (monitoring == null) return; + + monitoring.getThreadPoolProbeProvider().setMaxThreadsEvent( + threadPoolMonitoringName, maxPoolSize); + } + } + + @Override + protected void setPoolSizes(int corePoolSize, int maxPoolSize) { + synchronized (statelock) { + super.setPoolSizes(corePoolSize, maxPoolSize); + + if (monitoring == null) return; + + final ThreadPoolProbeProvider threadPoolProbeProvider = + monitoring.getThreadPoolProbeProvider(); + + threadPoolProbeProvider.setCoreThreadsEvent( + threadPoolMonitoringName, corePoolSize); + threadPoolProbeProvider.setMaxThreadsEvent( + threadPoolMonitoringName, maxPoolSize); + } + } + + + @Override protected void beforeExecute(Thread thread, Runnable runnable) { super.beforeExecute(thread, runnable); monitoring.getThreadPoolProbeProvider().threadDispatchedFromPoolEvent( @@ -84,6 +144,13 @@ super.afterExecute(r, t); } + @Override + protected void onWorkerExit(BasicWorker worker) { + monitoring.getThreadPoolProbeProvider().threadReleasedEvent( + threadPoolMonitoringName, Thread.currentThread().getName()); + super.onWorkerExit(worker); + } + public class ProbeWorkerThreadFactory implements ThreadFactory { @Override @@ -92,8 +159,8 @@ MonitorableThreadPool.this, r, name + "-(" + workerThreadCounter.getAndIncrement() + ")", initialByteBufferSize, monitoring); - monitoring.getThreadPoolProbeProvider().newThreadsAllocatedEvent( - threadPoolMonitoringName, 1, true); + monitoring.getThreadPoolProbeProvider().threadAllocatedEvent( + threadPoolMonitoringName, thread.getName()); return thread; } } Index: probes/ThreadPoolProbeProvider.java --- probes/ThreadPoolProbeProvider.java Base (BASE) +++ probes/ThreadPoolProbeProvider.java Locally Modified (Based On LOCAL) @@ -46,17 +46,33 @@ @ProbeProvider (moduleProviderName="glassfish", moduleName="kernel", probeProviderName="thread-pool") public class ThreadPoolProbeProvider { + @Probe(name="setMaxThreadsEvent") + public void setMaxThreadsEvent( + @ProbeParam("threadPoolName") String threadPoolName, + @ProbeParam("maxNumberOfThreads") int maxNumberOfThreads) {} + + + @Probe(name="setCoreThreadsEvent") + public void setCoreThreadsEvent( + @ProbeParam("threadPoolName") String threadPoolName, + @ProbeParam("coreNumberOfThreads") int coreNumberOfThreads) {} + /** * Emits notification that new thread was created and added to the * thread pool. */ - @Probe(name="newThreadsAllocatedEvent") - public void newThreadsAllocatedEvent( + @Probe(name="threadAllocatedEvent") + public void threadAllocatedEvent( @ProbeParam("threadPoolName") String threadPoolName, - @ProbeParam("increment") int increment, - @ProbeParam("startThread") boolean startThread) {} + @ProbeParam("threadId") String threadId) {} + @Probe(name="threadReleasedEvent") + public void threadReleasedEvent( + @ProbeParam("threadPoolName") String threadPoolName, + @ProbeParam("threadId") String threadId) {} + + @Probe(name="maxNumberOfThreadsReachedEvent") public void maxNumberOfThreadsReachedEvent( @ProbeParam("threadPoolName") String threadPoolName, Index: stats/ThreadPoolStatsProvider.java --- stats/ThreadPoolStatsProvider.java Base (BASE) +++ stats/ThreadPoolStatsProvider.java Locally Modified (Based On LOCAL) @@ -33,7 +33,6 @@ * only if the new code is made subject to such option by the copyright * holder. */ - package com.sun.enterprise.v3.services.impl.monitor.stats; import org.glassfish.external.probe.provider.annotations.ProbeListener; @@ -50,56 +49,100 @@ * * @author Alexey Stashok */ -@AMXMetadata(type="thread-pool-mon", group="monitoring") +@AMXMetadata(type = "thread-pool-mon", group = "monitoring") @ManagedObject @Description("Thread Pool Statistics") public class ThreadPoolStatsProvider { + private final String name; + private final CountStatisticImpl maxThreadsCount = new CountStatisticImpl("MaxThreads", "count", "Maximum number of threads allowed in the thread pool."); + private final CountStatisticImpl coreThreadsCount = new CountStatisticImpl("CoreThreads", "count", "Core number of threads in the thread pool."); - private final CountStatisticImpl totalExecutedTasksCount = new CountStatisticImpl("TotalExecutedTasksCount", "count", "Total number of tasks, which were executed by the thread-pool"); - private final CountStatisticImpl currentThreadPoolSize = new CountStatisticImpl("CurrentThreadPoolSize", "count", "Current number of threads running by the thread-pool"); - private final CountStatisticImpl numberOfActiveThreads = new CountStatisticImpl("NumberOfActiveThreads", "count", "Number of threads, which are currently executing tasks"); + private final CountStatisticImpl totalExecutedTasksCount = new CountStatisticImpl("TotalExecutedTasksCount", "count", "Provides the total number of tasks, which were executed by the thread pool."); + private final CountStatisticImpl currentThreadCount = new CountStatisticImpl("CurrentThreadCount", "count", "Provides the number of request processing threads currently in the listener thread pool."); + private final CountStatisticImpl currentThreadsBusy = new CountStatisticImpl("CurrentThreadsBusy", "count", "Provides the number of request processing threads currently in use in the listener thread pool serving requests."); public ThreadPoolStatsProvider(String name) { this.name = name; } - @ManagedAttribute(id="totalexecutedtasks") - @Description("Total number of tasks, which were executed by the thread-pool") - public CountStatistic getTotalExecutedTasksCount(){ + @ManagedAttribute(id = "maxthreads") + @Description("Maximum number of threads allowed in the thread pool.") + public CountStatistic getMaxThreadsCount() { + return maxThreadsCount; + } + + @ManagedAttribute(id = "corethreads") + @Description("Core number of threads in the thread pool.") + public CountStatistic getCoreThreadsCount() { + return coreThreadsCount; + } + + @ManagedAttribute(id = "totalexecutedtasks") + @Description("Provides the total number of tasks, which were executed by the thread pool.") + public CountStatistic getTotalExecutedTasksCount() { return totalExecutedTasksCount; } - @ManagedAttribute(id="currentthreadpoolsize") - @Description("Current number of threads running by the thread-pool") - public CountStatistic getCurrentThreadPoolSize(){ - return currentThreadPoolSize; + @ManagedAttribute(id = "currentthreadcount") + @Description("Provides the number of request processing threads currently in the listener thread pool.") + public CountStatistic getCurrentThreadCount() { + return currentThreadCount; } - @ManagedAttribute(id="numberofactivethreads") - @Description("Number of threads, which are currently executing tasks") - public CountStatistic getNumberOfActiveThreads(){ - return numberOfActiveThreads; + @ManagedAttribute(id = "currentthreadsbusy") + @Description("Provides the number of request processing threads currently in use in the listener thread pool serving requests.") + public CountStatistic getCurrentThreadsBusy() { + return currentThreadsBusy; } - @ProbeListener("glassfish:kernel:thread-pool:newThreadsAllocatedEvent") - public void newThreadsAllocatedEvent( + @ProbeListener("glassfish:kernel:thread-pool:setMaxThreadsEvent") + public void setMaxThreadsEvent( @ProbeParam("threadPoolName") String threadPoolName, - @ProbeParam("increment") int increment, - @ProbeParam("startThread") boolean startThread) { + @ProbeParam("maxNumberOfThreads") int maxNumberOfThreads) { if (name.equals(threadPoolName)) { - currentThreadPoolSize.increment(); + maxThreadsCount.setCount(maxNumberOfThreads); } } + @ProbeListener("glassfish:kernel:thread-pool:setCoreThreadsEvent") + public void setCoreThreadsEvent( + @ProbeParam("threadPoolName") String threadPoolName, + @ProbeParam("coreNumberOfThreads") int coreNumberOfThreads) { + + if (name.equals(threadPoolName)) { + coreThreadsCount.setCount(coreNumberOfThreads); + } + } + + @ProbeListener("glassfish:kernel:thread-pool:threadAllocatedEvent") + public void threadAllocatedEvent( + @ProbeParam("threadPoolName") String threadPoolName, + @ProbeParam("threadId") String threadId) { + + if (name.equals(threadPoolName)) { + currentThreadCount.increment(); + } + } + + @ProbeListener("glassfish:kernel:thread-pool:threadReleasedEvent") + public void threadReleasedEvent( + @ProbeParam("threadPoolName") String threadPoolName, + @ProbeParam("threadId") String threadId) { + + if (name.equals(threadPoolName)) { + currentThreadCount.decrement(); + } + } + @ProbeListener("glassfish:kernel:thread-pool:threadDispatchedFromPoolEvent") public void threadDispatchedFromPoolEvent( @ProbeParam("threadPoolName") String threadPoolName, @ProbeParam("threadId") String threadId) { if (name.equals(threadPoolName)) { - numberOfActiveThreads.increment(); + currentThreadsBusy.increment(); } } @@ -110,7 +153,7 @@ if (name.equals(threadPoolName)) { totalExecutedTasksCount.increment(); - numberOfActiveThreads.decrement(); + currentThreadsBusy.decrement(); } } }