Skip to content

Commit

Permalink
TECH-1808 Avoid using static Executor avoiding OSGI stop and start is…
Browse files Browse the repository at this point in the history
…sues
  • Loading branch information
jayblanc authored and jkevan committed Jun 10, 2024
1 parent 77da2a7 commit a868e39
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

@Component(immediate = true, service = LoadAverageService.class)
@Component(immediate = true, service = LoadAverageService.class, scope = ServiceScope.SINGLETON)
public class LoadAverageServiceImpl implements LoadAverageService {

private static final Logger LOGGER = LoggerFactory.getLogger(LoadAverageService.class);
private static final ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
@Reference(service = LoadAverageProvider.class, cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC,
bind = "addProvider", unbind = "removeProvider")
private volatile List<LoadAverageProvider> providers = new ArrayList<>();
private final ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
private final Map<String, ScheduledFuture<?>> schedules = new HashMap<>();
private long calcFreqMillis = 5000;
private boolean running = false;
Expand All @@ -72,7 +72,7 @@ public void addProvider(LoadAverageProvider provider) {
schedules.get(provider.getClass().getName()).cancel(false);
schedules.remove(provider.getClass().getName());
}
if (running && !executor.isShutdown() && !executor.isTerminated()) {
if (running) {
ScheduledFuture<?> scheduledFuture =
executor.scheduleAtFixedRate(provider, 0, calcFreqMillis, TimeUnit.MILLISECONDS);
schedules.put(provider.getClass().getName(), scheduledFuture);
Expand Down

0 comments on commit a868e39

Please sign in to comment.