Source:
private void restartJobs() { logger.debug("Restarting jobs for thing {}", getThing().getUID()); if (schedulerFuture != null && !schedulerFuture.isCancelled()) { schedulerFuture.cancel(true); } schedulerFuture = scheduler.schedule(() -> { try { stopJobs(); monitor.lock(); if (getThing().getStatus() == ONLINE) { final String thingUID = getThing().getUID().toString(); final String typeId = getThing().getThingTypeUID().getId(); final Optional<Job> dailyJob = getDailyJob(); if (!dailyJob.isPresent()) { logger.error("Daily Job instance not present"); return; } if (!scheduledExecutor.isPresent()) { logger.warn("Thread Pool Executor is not available"); return; } final ExpressionThreadPoolExecutor executor = scheduledExecutor.get(); final Expression midNightExpression = new CronExpression(DAILY_MIDNIGHT); executor.schedule(dailyJob.get(), midNightExpression); logger.info("Scheduled astro job-daily-{} at midnight for thing {}", typeId, thingUID); final Calendar now = Calendar.getInstance(); final Expression dateExpression = new CronExpression(createCronFromDate(now.getTime())); executor.schedule(dailyJob.get(), dateExpression); logger.info("Scheduled astro job-startup-{} for thing {}", typeId, thingUID); final Date start = new Date(System.currentTimeMillis() + thingConfig.getInterval() * 1000); if (isPositionalChannelLinked()) { final Expression expression = new CronExpression( createCronForRepeatEverySeconds(thingConfig.getInterval()), start); final Job positionalJob = new PositionalJob(thingUID); executor.schedule(positionalJob, expression); logger.info("Scheduled astro job-positional with interval of seconds for thing {}", thingConfig.getInterval(), thingUID); } } } catch (final ParseException ex) { logger.error("{}", ex.getMessage(), ex); } finally { monitor.unlock(); } }, DELAY, MILLISECONDS); }

Target:
private void restartJobs() { logger.debug("Restarting jobs for thing {}", getThing().getUID()); if (schedulerFuture != null && !schedulerFuture.isCancelled()) { schedulerFuture.cancel(true); } if (localExecutor != null) { localExecutor.shutdownNow(); } localExecutor = Executors.newSingleThreadExecutor(); schedulerFuture = scheduler.schedule(() -> { monitor.lock(); try { stopJobs(); if (getThing().getStatus() == ONLINE) { String thingUID = getThing().getUID().toString(); String typeId = getThing().getThingTypeUID().getId(); Job dailyJob = getDailyJob(); if (dailyJob == null) { logger.error("Daily Job instance not present"); return; } if (scheduledExecutor == null) { logger.warn("Thread Pool Executor is not available"); return; } Expression midNightExpression = new CronExpression(DAILY_MIDNIGHT); if (addJobToQueue(dailyJob)) { scheduledExecutor.schedule(dailyJob, midNightExpression); logger.info("Scheduled astro job-daily-{} at midnight for thing {}", typeId, thingUID); } localExecutor.submit(dailyJob); LocalDateTime currentTime = LocalDateTime.now(); LocalDateTime futureTimeWithInterval = currentTime.plusSeconds(thingConfig.getInterval()); Date start = Date.from(futureTimeWithInterval.atZone(ZoneId.systemDefault()).toInstant()); if (isPositionalChannelLinked()) { Expression expression = new CronExpression( createCronForRepeatEverySeconds(thingConfig.getInterval()), start); Job positionalJob = new PositionalJob(thingUID); if (addJobToQueue(positionalJob)) { scheduledExecutor.schedule(positionalJob, expression); logger.info("Scheduled astro job-positional with interval of seconds for thing {}", thingConfig.getInterval(), thingUID); } localExecutor.submit(positionalJob); } } } catch (ParseException ex) { logger.error("{}", ex.getMessage(), ex); } finally { monitor.unlock(); } }, DELAY, MILLISECONDS); }