private boolean doDestroy ( ) { // Try to obtain the scan lock to destroy all associated monitors // Other users of the scanLock should check the destroy flag // before they release the lock to determine whether or not // resources should be destroyed if ( scanLock . tryLock ( ) ) { try { if ( monitorState . compareAndSet ( MonitorState . DESTROY . ordinal ( ) , MonitorState . DESTROYED . ordinal ( ) ) ) { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isEventEnabled ( ) ) { Tr . event ( this , tc , "Destroy file monitor" ) ; } for ( UpdateMonitor m : updateMonitors . keySet ( ) ) { m . destroy ( ) ; } updateMonitors . clear ( ) ; // Clear any unnotified file changes, these will become invalid // as the monitors are destroyed. unnotifiedFileCreates . clear ( ) ; unnotifiedFileDeletes . clear ( ) ; unnotifiedFileModifies . clear ( ) ; return true ; // monitor was destroyed } } finally { scanLock . unlock ( ) ; } } // Also return true if monitor was already destroyed return monitorState . get ( ) == MonitorState . DESTROYED . ordinal ( ) ; }
Will actually destroy the monitors if and only if the monitor state has already been set to DESTROY .