CacheManager cacheManager2 = CacheManager.newInstance(configFile);
Cache cache2 = cacheManager2.getCache("test");
Element element = cache2.get("e1");
Object objectValue = element.getObjectValue();
System.out.println(objectValue);
cacheManager2.shutdown();
Using the attached config file for the creation of the CacheManager caches are persisted to disk.
Steps are:
(1) create first CacheManager, store an element in cache "test" and shutdown the first CacheManager
(2) create second CacheManager, retrieve the element from cache "test" and shutdown the second CacheManager
(3) then the test tries to delete the folder containing the disk store and fails
It looks to me like there are file handles kept open due to (2). Deleting the disk store after (1) works fine.
When you create the second cache manager the manager will run recovery over the data files created by the first cache manager instance. This recovery process create file mappings the unmapping of which is handled by the garbage collector. Since Windows doesn't allow the deletion of files with a mapped region open you won't be able to delete these files until after the GC runs and unmaps the mapped files. You don't quote the exception you get but I'm guessing it complains about not being able to delete a file with a mapped region open.
You really have two ways of getting round this:
1. Call System.gc() a bunch of times and wait for the GC to unmap the file.
2. Use unique file names - you might also be able to use deleteOnExit(...) successfully here.