Skip to content

Commit

Permalink
Fix an issue with cancel/enable monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
IndikaKuma committed Jul 31, 2020
1 parent 763154b commit f1013b8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public Response enableDisableMonitoring(@DefaultValue("disabled") @QueryParam("s
return Response.status(500).entity(e.getMessage()).build();
}
} else {
monitoringDataCollector.shutdown();
monitoringDataCollector.cancelTask();
return Response.status(200).entity("Monitoring Disabled/Stopped").build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,27 @@

import java.util.TimerTask;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class MonitoringDataCollector {
private ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
private TimerTask repeatedTask = new MonitoringTimerTask();
private Future<?> future;

public void start()
throws InterruptedException {
long delay = 1000L;
long period = 1000L;
System.out.println("Monitoring Data Collector Started");
executor.scheduleAtFixedRate(repeatedTask, delay, period, TimeUnit.MILLISECONDS);
//get reference to the future
future = executor.scheduleAtFixedRate(repeatedTask, delay, period, TimeUnit.MILLISECONDS);
}

public void cancelTask() {
System.out.println("Canceling Monitoring Task");
future.cancel(false);
}

public void shutdown() {
Expand Down

0 comments on commit f1013b8

Please sign in to comment.