@Override
    public void stop(){
        if (isStarted.compareAndSet(true,false)) {
            // if you shutdown it, it can not be use anymore
            super.stop();
            ScheduledExecutorService service = this.syncService.getAndSet(newSyncService());
            service.shutdown();
            LOGGER.info("Cache sync Service is shutdown");
            for (Entry<String,ModelServiceClientCache> entry : cache.entrySet()){
               removeInstanceChangeListener(entry.getKey(),entry.getValue());
            }
            getCache().clear();
        }
    }
@ Override public void stop ( ) { if ( isStarted . compareAndSet ( true , false ) ) { super . stop ( ) ; ScheduledExecutorService service = this . syncService . getAndSet ( newSyncService ( ) ) ; service . shutdown ( ) ; LOGGER . info ( "Cache sync Service is shutdown" ) ; for ( Entry < String , ModelServiceClientCache > entry : cache . entrySet ( ) ) { removeInstanceChangeListener ( entry . getKey ( ) , entry . getValue ( ) ) ; } getCache ( ) . clear ( ) ; } }
Stop the CachedDirectoryLookupService.

It is thread safe.