+ boolean need_monitor() {
+ return reader.opened() && !callbacks.isEmpty();
+ }
+
+ void maybe_stop_monitor() {
+ if (!need_monitor() && monitor_thread != null) {
+ monitor_thread.interrupt();
+ try {
+ monitor_thread.join();
+ } catch (InterruptedException e) {
+ } finally {
+ monitor_thread = null;
+ }
+ }
+ }
+
+ void maybe_start_monitor() {
+ if (need_monitor() && monitor_thread == null) {
+ monitor_thread = new Thread(this);
+ monitor_thread.start();