@Override
                    public synchronized void onTimeChange(long currentTimestamp) {
                        Map<String, Map<String, SchedulerState>> allStates = stateHolder.getAllStates();
                        try {
                            TreeMultimap<Long, SchedulerState> sortedExpires = TreeMultimap.create();
                            for (Map.Entry<String, Map<String, SchedulerState>> allStatesEntry :
                                    allStates.entrySet()) {
                                for (Map.Entry<String, SchedulerState> stateEntry :
                                        allStatesEntry.getValue().entrySet()) {
                                    Long lastTime = stateEntry.getValue().toNotifyQueue.peek();
                                    if (lastTime != null && lastTime <= currentTimestamp) {
                                        sortedExpires.put(lastTime, stateEntry.getValue());
                                    }
                                }
                            }
                            for (Map.Entry<Long, SchedulerState> entry : sortedExpires.entries()) {
                                try {
                                    SiddhiAppContext.startPartitionFlow(entry.getValue().key);
                                    // If executed in a separate thread, while it is processing,
                                    // the new event will come into the window. As the result of it,
                                    // the window will emit the new event as an existing current event.
                                    sendTimerEvents(entry.getValue());
                                } finally {
                                    SiddhiAppContext.stopPartitionFlow();
                                }
                            }
                        } finally {
                            stateHolder.returnAllStates(allStates);
                        }
                    }
Scheduler implementation to take periodic snapshots
modules/siddhi-core/src/main/java/io/siddhi/core/util/Scheduler.java