Made the change based on Amareshwari's suggestions.
Shall we rename the class BaseDir to something like BaseDirManager?
That's a very good name. I have changed it.
cacheStatus.baseDir is being accessed under global lock in BaseDir.checkAndCleanup() method, every-where else it is accessed under CacheStatus lock. I think it is no harm. Can you also check this once and add a comment?
I have made baseDir immutable
Though not related to this issue, can you add a comment for CacheStatus.refCount saying it should be always accessed under the global cachedArchives lock.
I have add comments on all fields in CacheStatus to explain how to access them.
catch(InterruptedException) block in CleanupThread can do a return instead of ignoring the exception.
I think cleanup thread should catch all Exceptions (not just IOException) because thread should never crash, similar to CleanupQueue.
Now it catches all exceptions, logs them and keeps running.
Test case can call baseDir.checkAndCleanup() inline to avoid timing issues, what do you think?
I feel that it is better to test the whole CleanupThread. That way we can make sure the thread actually does the right thing.