-
Notifications
You must be signed in to change notification settings - Fork 143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow shutdown of executors, to clean up resources. #62
base: master
Are you sure you want to change the base?
Conversation
Works fine when tested alone, but fails when executed with others, due probably to `EmpiringMapTest.testSetThreadFactory` doing `EXPIRER = null` and, thus, losing all old threads.
@@ -1382,4 +1382,15 @@ public V setValue(V value) { | |||
} | |||
}; | |||
} | |||
|
|||
public synchronized static void shutdown() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we get some javadoc here indicating what this method does? It should mention when and why you might want to use it, and that it affects all ExpiringMap instances.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, will add it as soon as I'm back in the office.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(sorry, I was on other projects and time has flown by)
While this is a straightforward change, it's also potentially dangerous since calling The only alternative to having something like In terms of the effect of a shutdown, I'd be interested to see if we could recover existing expiringmaps by re-initializing the Anyone care to weigh in on this issue? |
I need that too, it's a meaningful pull request! I have exactly the same use case too, killing the threads when undeploying a webapp from a tomcat. ...otherwise you have to bring the whole Tomcat down, which is a bit bothersome. I guess it would be ideal to provide both: to kill all ExpiringMap instances, or to kill just "yours". |
Agreed this Of course this is dangerous because these are global, static instances. But this is necessary with the current code. A better way for application wanting isolation would be to allow the thread pool and executor to be contributable from the builder. |
How about making the expirer and expiration listener thread pools configurable, then the user can shut them down if they want. I left a few additional comments on that here. This wouldn't necessarily require a shutdown API since users could shutdown the threadpools externally. That would of course require that users either maintain a reference to the threadpools, or ExpiringMap could have APIs to As for shutting down the shared, static threadpools, I'm not really in favor of that since it would have an affect on all ExpiringMap instances. For the same reason, I'm unsure of having a Thoughts on this? |
Any news on this? This shutdown hook is still very welcome! |
Being able to define a "local threadpool" at build time (and thus being able to shutdown only my own and not everyone's) would be fine by me, but when a WAR is undeploying (and ExpiringMap is about to be removed from the classloaders) a global shutdown is still fine. OTOH I know that |
AFAICT |
Proper cleanup of resource, avoid problems e.g. on Tomcat undeploy, which currently generates:
In this way it has to be called manually, but it's more generic.
Another approach could be to auto-register a context listener to automatically shutdown, like logback is doing or using a
@WebListener
annotation.