diff options
Diffstat (limited to 'src/main/scala/akka/PoolMonitorAspect.scala')
-rw-r--r-- | src/main/scala/akka/PoolMonitorAspect.scala | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/main/scala/akka/PoolMonitorAspect.scala b/src/main/scala/akka/PoolMonitorAspect.scala new file mode 100644 index 00000000..c6c4e4a5 --- /dev/null +++ b/src/main/scala/akka/PoolMonitorAspect.scala @@ -0,0 +1,29 @@ +package akka + +import org.aspectj.lang.annotation.{Pointcut, Before, Aspect} +import java.util.concurrent.{TimeUnit, Executors} + +@Aspect +class PoolMonitorAspect { + + @Pointcut("execution(scala.concurrent.forkjoin.ForkJoinPool.new(..))") + protected def poolMonitor:Unit = {} + + @Before("poolMonitor() && this(pool)") + def beforePoolInstantiation(pool: scala.concurrent.forkjoin.ForkJoinPool) { + + val scheduler = Executors.newScheduledThreadPool(1); + + scheduler.scheduleAtFixedRate(new Runnable { + def run() { + println("PoolName : " + pool.getClass.getSimpleName) + println("ThreadCount :" + pool.getActiveThreadCount) + println("Parallelism :" + pool.getParallelism) + println("PoolSize :" + pool.getPoolSize()) + println("Submission :" + pool.getQueuedSubmissionCount()) + println("Steals :" + pool.getStealCount()) + println("All :" + pool.toString) + } + }, 4, 4, TimeUnit.SECONDS) + } +} |