keenlabs / KeenClient-Java

Official Java client for the Keen IO API. Build analytics features directly into your Java apps.
https://keen.io/docs
MIT License
74 stars 43 forks source link

Thread pool prevents Tomcat from shutting down #3

Closed karlvr closed 11 years ago

karlvr commented 11 years ago

We're seeing this issue in our app. The KeenClient creates the ExecutorService which keeps threads alive and prevents Tomcat from shutting down.

There is some discussion about the issue here: http://stackoverflow.com/questions/12815614/shutdown-executorservice-gracefully-in-webapp

I believe there should be a method on KeenClient to shutdown and await termination of the executor service. That would push the burden onto the user, but would allow any situation to be catered for.

Perhaps it would be possible to annotate the class with "@WebListener" as per these instructions http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContextListener.html#contextDestroyed%28javax.servlet.ServletContextEvent%29 and to then implement the ServletContextListener. However this would introduce a dependency on the servlet api. Perhaps you could create a new subclass of KeenClient called KeenWebClient which did that?

I'm happy to contribute a pull request. I'm just not sure of the best approach :-)

dkador commented 11 years ago

I'd rather not build in a dependency on the servlet API at all. I'd be happy to have a shutdown method, though. That seems good to me. I'd love to see a pull request from you.

FYI, there is a workaround today... but it's cludgy:

  1. Set KeenConfig.NUM_THREADS_FOR_HTTP_REQUEST to 0.
  2. Subclass KeenClient and override processRunnableInNewThread().