I need to monitor the property value has changed or not throughout the java program run, if its value has changed in need to do some necessary steps to handle the changed value.
I have used scheduleWithFixedDelay service to monitor value and observer pattern to take necessary action.
ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);
scheduledExecutorService.scheduleWithFixedDelay(() -> {
myClass2.scanValueChanged();
},1,45, TimeUnit.SECONDS);
Since scheduledExecutorService and main thread run parallel, by the time I handled in scheduledExecutorService the main method runs executes the block of the code and fails with the expected outcome.
Is there a way when scheduledExecutorService is running that I can pause the main thread?