EHC ❯ CacheManager shutdown hook could use some clean up
-
Bug
-
Status: Resolved
-
2 Major
-
Resolution: Won't Fix
-
ehcache-core
-
-
teck
-
Reporter: amiller
-
October 30, 2009
-
0
-
Watchers: 2
-
August 21, 2013
-
August 21, 2013
Description
The shutdown hook code looks like it could be cleaned up a bit. There is a synchronized(this) that occurs on the shutdown hook thread and serves no purpose here:
Thread localShutdownHook = new Thread() {
@Override
public void run() {
synchronized (this) {
if (status.equals(Status.STATUS_ALIVE)) {
// clear shutdown hook reference to prevent
// removeShutdownHook to remove it during shutdown
shutdownHook = null;
if (LOG.isLoggable(Level.INFO)) {
LOG.log(Level.INFO, "VM shutting down with the CacheManager still active. Calling shutdown.");
}
shutdown();
}
}
}
};
It also seems like the removal of the shutdown hook to prevent memory leaks could be handled by not using an inner class and possibly using a WeakReference back to the CacheManager.
Comments
Tim Eck 2009-10-30
Fiona OShea 2010-08-11
Is this still even an issue?
Tim Eck 2010-08-12
the particular synchronization mentioned is stupid and serves no purpose (other than to confuse the reader). Beyond that it doesn’t hurt.
I don’t have any particular motivation to take up the task of replacing this shutdown hook with something based on weak references
perhaps that logic is better suited for a synchronized method back on the enclosing cachemanager instance?