/** * Tells the background thread to start. Does not wait for it to be running. * Calling this method more than once has no effect. */ public void start() { if (!compareAndSetState(State.NEW, State.STARTING)) { // If previous state was not NEW, start() has already been called. return; } this.watcherThread.start(); }
/** * Tells the background thread to stop. Does not wait for it to exit. */ public void stop() { if (compareAndSetState( new State[]{State.RUNNING, State.STARTING}, State.STOPPING)) { watcherThread.interrupt(); } }