Class InstrumentedExecutorService

  • All Implemented Interfaces:
    java.util.concurrent.Executor, java.util.concurrent.ExecutorService

    public class InstrumentedExecutorService
    extends java.lang.Object
    implements java.util.concurrent.ExecutorService
    A wrapper around InstrumentedExecutorService that allows the metrics to be reset by MetricsSystem.resetAllMetrics(). Additional it tracks in a histogram called name.active.tasks the number of active tasks (queued or running) each time a new task is added to the executor. This histogram is additionally tracks the maximum overall number active tasks at any time.
    • Constructor Summary

      Constructors 
      Constructor Description
      InstrumentedExecutorService​(java.util.concurrent.ExecutorService executorService, com.codahale.metrics.MetricRegistry registry, java.lang.String name)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean awaitTermination​(long l, java.util.concurrent.TimeUnit timeUnit)  
      void execute​(java.lang.Runnable runnable)  
      <T> java.util.List<java.util.concurrent.Future<T>> invokeAll​(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks)  
      <T> java.util.List<java.util.concurrent.Future<T>> invokeAll​(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks, long timeout, java.util.concurrent.TimeUnit unit)  
      <T> T invokeAny​(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks)  
      <T> T invokeAny​(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks, long timeout, java.util.concurrent.TimeUnit unit)  
      boolean isShutdown()  
      boolean isTerminated()  
      protected void reset()
      Resets the metrics monitored about the executor service.
      void shutdown()  
      java.util.List<java.lang.Runnable> shutdownNow()  
      java.util.concurrent.Future<?> submit​(java.lang.Runnable runnable)  
      <T> java.util.concurrent.Future<T> submit​(java.lang.Runnable runnable, T result)  
      <T> java.util.concurrent.Future<T> submit​(java.util.concurrent.Callable<T> task)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • InstrumentedExecutorService

        public InstrumentedExecutorService​(java.util.concurrent.ExecutorService executorService,
                                           com.codahale.metrics.MetricRegistry registry,
                                           java.lang.String name)
        Parameters:
        executorService - the executor service to instrument
        registry - the metric registry
        name - the name that will be used for the associated metrics
    • Method Detail

      • reset

        protected void reset()
        Resets the metrics monitored about the executor service. This is only called by MetricsSystem.resetAllMetrics() after all metrics have already been cleared, then this method will update the pointers of this object to the new metrics.
      • execute

        public void execute​(@Nonnull
                            java.lang.Runnable runnable)
        Specified by:
        execute in interface java.util.concurrent.Executor
      • submit

        public java.util.concurrent.Future<?> submit​(@Nonnull
                                                     java.lang.Runnable runnable)
        Specified by:
        submit in interface java.util.concurrent.ExecutorService
      • submit

        public <T> java.util.concurrent.Future<T> submit​(@Nonnull
                                                         java.lang.Runnable runnable,
                                                         T result)
        Specified by:
        submit in interface java.util.concurrent.ExecutorService
      • submit

        public <T> java.util.concurrent.Future<T> submit​(@Nonnull
                                                         java.util.concurrent.Callable<T> task)
        Specified by:
        submit in interface java.util.concurrent.ExecutorService
      • invokeAll

        public <T> java.util.List<java.util.concurrent.Future<T>> invokeAll​(@Nonnull
                                                                            java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks)
                                                                     throws java.lang.InterruptedException
        Specified by:
        invokeAll in interface java.util.concurrent.ExecutorService
        Throws:
        java.lang.InterruptedException
      • invokeAll

        public <T> java.util.List<java.util.concurrent.Future<T>> invokeAll​(@Nonnull
                                                                            java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks,
                                                                            long timeout,
                                                                            @Nonnull
                                                                            java.util.concurrent.TimeUnit unit)
                                                                     throws java.lang.InterruptedException
        Specified by:
        invokeAll in interface java.util.concurrent.ExecutorService
        Throws:
        java.lang.InterruptedException
      • invokeAny

        public <T> T invokeAny​(@Nonnull
                               java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks)
                        throws java.util.concurrent.ExecutionException,
                               java.lang.InterruptedException
        Specified by:
        invokeAny in interface java.util.concurrent.ExecutorService
        Throws:
        java.util.concurrent.ExecutionException
        java.lang.InterruptedException
      • invokeAny

        public <T> T invokeAny​(@Nonnull
                               java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks,
                               long timeout,
                               @Nonnull
                               java.util.concurrent.TimeUnit unit)
                        throws java.util.concurrent.ExecutionException,
                               java.lang.InterruptedException,
                               java.util.concurrent.TimeoutException
        Specified by:
        invokeAny in interface java.util.concurrent.ExecutorService
        Throws:
        java.util.concurrent.ExecutionException
        java.lang.InterruptedException
        java.util.concurrent.TimeoutException
      • shutdown

        public void shutdown()
        Specified by:
        shutdown in interface java.util.concurrent.ExecutorService
      • shutdownNow

        public java.util.List<java.lang.Runnable> shutdownNow()
        Specified by:
        shutdownNow in interface java.util.concurrent.ExecutorService
      • isShutdown

        public boolean isShutdown()
        Specified by:
        isShutdown in interface java.util.concurrent.ExecutorService
      • isTerminated

        public boolean isTerminated()
        Specified by:
        isTerminated in interface java.util.concurrent.ExecutorService
      • awaitTermination

        public boolean awaitTermination​(long l,
                                        @Nonnull
                                        java.util.concurrent.TimeUnit timeUnit)
                                 throws java.lang.InterruptedException
        Specified by:
        awaitTermination in interface java.util.concurrent.ExecutorService
        Throws:
        java.lang.InterruptedException