Calling cancel from within an event handler ends up being completely ignored by the ScheduledService, because after the event handlers do their business, it then schedules up the next request. We need to remember when somebody has cancelled, so that on the next iteration we can just stop.
GetNetworkInterfacesService networkInterfacesService = new GetNetworkInterfacesService();
networkInterfacesService.setPeriod(Duration.seconds(1));
networkInterfacesService.setOnSucceeded(event -> {
networkInterfacesService.cancel();
});
networkInterfacesService.start();
GetNetworkInterfacesService networkInterfacesService = new GetNetworkInterfacesService();
networkInterfacesService.setPeriod(Duration.seconds(1));
networkInterfacesService.setOnSucceeded(event -> {
networkInterfacesService.cancel();
});
networkInterfacesService.start();