private void schedule(long time, SchedulerState state, boolean force) {
        if (!siddhiQueryContext.getSiddhiAppContext().isPlayback()) {
            if (!state.running && (state.toNotifyQueue.size() == 1 || force)) {
                try {
                    mutex.acquire();
                    if (!state.running) {
                        state.running = true;
                        long timeDiff = time - siddhiQueryContext.getSiddhiAppContext().
                                getTimestampGenerator().currentTime();
                        if (timeDiff > 0) {
                            state.scheduledFuture = scheduledExecutorService.schedule(state.eventCaller,
                                    timeDiff, TimeUnit.MILLISECONDS);
                        } else {
                            state.scheduledFuture = scheduledExecutorService.schedule(state.eventCaller,
                                    0, TimeUnit.MILLISECONDS);
                        }
                    }

                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                    log.error("Error when scheduling System Time Based Scheduler", e);
                } finally {
                    mutex.release();
                }
            }
        }
    }
Scheduler implementation to take periodic snapshots
modules/siddhi-core/src/main/java/io/siddhi/core/util/Scheduler.java