/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package com.sun.enterprise.v3.services.impl.monitor.stats; import java.util.concurrent.atomic.AtomicInteger; import org.glassfish.gmbal.ManagedAttribute; import org.glassfish.gmbal.ManagedObject; import org.glassfish.probe.provider.annotations.ProbeListener; import org.glassfish.probe.provider.annotations.ProbeParam; /** * * @author oleksiys */ @ManagedObject public class ThreadPoolStatsProvider { private AtomicInteger totalExecutedTasksCount = new AtomicInteger(); private AtomicInteger currentThreadPoolSize = new AtomicInteger(); private AtomicInteger numberOfActiveThreads = new AtomicInteger(); @ManagedAttribute(id="totalExecutedTasksCount") public int getTotalExecutedTasksCount(){ return totalExecutedTasksCount.get(); } @ManagedAttribute(id="currentThreadPoolSize") public int getCurrentThreadPoolSize(){ return currentThreadPoolSize.get(); } @ManagedAttribute(id="numberOfActiveThreads") public int getNumberOfActiveThreads(){ return numberOfActiveThreads.get(); } @ProbeListener("glassfish:kernel:grizzly:threadsallocated") public void newThreadsAllocatedEvent( @ProbeParam("threadPoolName") String threadPoolName, @ProbeParam("increment") int increment, @ProbeParam("startThread") boolean startThread) { System.out.println("newThreadsAllocatedEvent callback"); currentThreadPoolSize.incrementAndGet(); } @ProbeListener("glassfish:kernel:grizzly:threaddispatched") public void threadDispatchedFromPoolEvent( @ProbeParam("threadPoolName") String threadPoolName, @ProbeParam("threadId") String threadId) { System.out.println("threadDispatchedFromPoolEvent callback"); numberOfActiveThreads.incrementAndGet(); } @ProbeListener("glassfish:kernel:grizzly:threadreturned") public void threadReturnedToPoolEvent( @ProbeParam("threadPoolName") String threadPoolName, @ProbeParam("threadId") String threadId) { System.out.println("threadReturnedToPoolEvent callback"); totalExecutedTasksCount.incrementAndGet(); numberOfActiveThreads.decrementAndGet(); } }