Class MetricsPersisterJob
java.lang.Object
com.j256.simplemetrics.persister.MetricsPersisterJob
- All Implemented Interfaces:
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 Summary
ConstructorsConstructorDescriptionMetricsPersisterJob(MetricsManager metricsManager, long delayTimeMillis, long periodTimeMillis, boolean daemonThread) Create the MetricsPersisterThread and callsinitialize(). -
Method Summary
Modifier and TypeMethodDescriptionvoiddestroy()Call when you want to shutdown the publisher thread.voidCall when you want to destroy the background persisting thread and then wait for it to finish.voidShould be called if the no-arg construct is being used and after the file metrics have been set.voidjoin()Deprecated.voidrun()Run by the thread to persist the metrics by callingMetricsManager.persist().voidsetDaemonThread(boolean daemonThread) Whether or not the thread is a daemon thread.voidsetDelayTimeMillis(long delayTimeMillis) Number of millis to sleep when the thread starts before we start persisting.voidsetMetricsManager(MetricsManager metricsManager) voidsetPeriodTimeMillis(long periodTimeMillis) Number of millis to sleep between each persisting call.
-
Constructor Details
-
MetricsPersisterJob
public MetricsPersisterJob() -
MetricsPersisterJob
public MetricsPersisterJob(MetricsManager metricsManager, long delayTimeMillis, long periodTimeMillis, boolean daemonThread) Create the MetricsPersisterThread and callsinitialize().
-
-
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 calldestroyAndJoin()if you want to destroy the thread _and_ join with it after it has terminated. -
join
Deprecated.Should usedestroyAndJoin(). -
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 callingMetricsManager.persist(). -
setMetricsManager
-
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.
-
destroyAndJoin().