+ persister_thread = new Thread(() -> {
+ long lastTimerTick = System.currentTimeMillis();
+ while (true) {
+ boolean need_persist = this.channel_manager.await_persistable_update_timeout(1);
+ Event[] events = this.channel_manager.as_EventsProvider().get_and_clear_pending_events();
+ if (events.length != 0) {
+ persister.handle_events(events);
+ need_persist = true;
+ }
+ events = this.chain_monitor.as_EventsProvider().get_and_clear_pending_events();
+
+ if (events.length != 0) {
+ persister.handle_events(events);
+ need_persist = true;
+ }
+ if (need_persist) {
+ persister.persist_manager(this.channel_manager.write());
+ }
+ if (shutdown) {
+ return;
+ }
+ if (lastTimerTick < System.currentTimeMillis() - 60 * 1000) {
+ this.channel_manager.timer_tick_occurred();
+ lastTimerTick = System.currentTimeMillis();
+ }
+ }
+ }, "NioPeerHandler NIO Thread");
+ persister_thread.start();
+ }
+
+ /**
+ * Interrupt the background thread, stopping the background handling of
+ */
+ public void interrupt() {
+ shutdown = true;
+ try {
+ persister_thread.join();
+ } catch (InterruptedException ignored) { }