Class MetricsPersisterJob

java.lang.Object
com.j256.simplemetrics.persister.MetricsPersisterJob
All Implemented Interfaces:
Runnable

public class MetricsPersisterJob extends Object implements Runnable
Metrics persister thread that can be used to call MetricsManager.persistValuesOnly() at a specific frequency. This is used if you don't have another mechanism to call the persisting on your own. If you are using the no-arg constructor (like with Spring) you will need to make sure that initialize() is called.
Author:
graywatson
  • Constructor Details

    • MetricsPersisterJob

      public MetricsPersisterJob()
    • MetricsPersisterJob

      public MetricsPersisterJob(MetricsManager metricsManager, long delayTimeMillis, long periodTimeMillis, boolean daemonThread)
      Create the MetricsPersisterThread and calls initialize().
  • Method Details

    • initialize

      public void initialize()
      Should be called if the no-arg construct is being used and after the file metrics have been set. Maybe by Spring's init mechanism?
    • destroy

      public void destroy()
      Call when you want to shutdown the publisher thread. You should call destroyAndJoin() if you want to destroy the thread _and_ join with it after it has terminated.
    • join

      @Deprecated public void join()
      Deprecated.
      Should use destroyAndJoin().
    • destroyAndJoin

      public void destroyAndJoin()
      Call when you want to destroy the background persisting thread and then wait for it to finish.
    • run

      public void run()
      Run by the thread to persist the metrics by calling MetricsManager.persist().
      Specified by:
      run in interface Runnable
    • setMetricsManager

      public void setMetricsManager(MetricsManager metricsManager)
    • setDelayTimeMillis

      public void setDelayTimeMillis(long delayTimeMillis)
      Number of millis to sleep when the thread starts before we start persisting. By default this is the same as the period-time-millis.
    • setPeriodTimeMillis

      public void setPeriodTimeMillis(long periodTimeMillis)
      Number of millis to sleep between each persisting call.
    • setDaemonThread

      public void setDaemonThread(boolean daemonThread)
      Whether or not the thread is a daemon thread. If true then the JVM will quit even if this thread is still running.