Skip to content

Commit

Permalink
Merge pull request #11 from kr-pawan/master
Browse files Browse the repository at this point in the history
DEPL-12726 - added shutdown method to shutdown executor service
  • Loading branch information
mevdschee committed Jan 12, 2018
2 parents 67072ce + ebadb06 commit b891e2f
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ abstract class InfluxDbReporter {
*/
protected final MetricRegistry registry;

private final ScheduledExecutorService exec;

/**
* Instantiates a new JMX reporter.
*
Expand All @@ -54,6 +56,7 @@ abstract class InfluxDbReporter {
public InfluxDbReporter(MetricRegistry registry, String instanceName) {
this.instanceName = instanceName;
this.registry = registry;
this.exec = Executors.newSingleThreadScheduledExecutor();
}

/**
Expand Down Expand Up @@ -101,7 +104,13 @@ public void write(OutputStream out) {
* the interval in seconds
*/
public void run(int intervalInSeconds) {
ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor();
exec.scheduleAtFixedRate(() -> this.report(), 1, intervalInSeconds, TimeUnit.SECONDS);
}
}

/**
* Handler for shutdown of Executor service.
*/
public void shutdown() {
this.exec.shutdown();
}
}

0 comments on commit b891e2f

Please sign in to comment.