On 3/28/2018 1:18 PM, Christopher Schultz wrote: > > I would like to write a logging thread that can get ALL of the > > datasource objects from the context, and for types that it knows, > > cast them to the appropriate object to log the active/idle > > connection counts. > > It might be easier to do this via JMX.
Perhaps. But then I have to figure out how to get the program started with the sysprops that enable remote JMX. The system has no GUI, and we don't have any X-Windows infrastructure, so running JDK tools locally on the Linux server is challenging. Not impossible, just requires me to set up things that I don't already have, to do X forwarding over SSH. With the logging thread idea, we just need to update code, recompile, and redeploy. > Since you already have a compile-time dependency upon Tomcat, there's > no need to do class-name matching. Instead, just use "instanceof" as > before: I did the code that way so that I can handle any type of DataSource object, even if we change our pool configurations, just by adding stanzas to the switch. And the default case logs the class name if it's not handled explicitly, so I know what to add or change. I went looking for a way to write a switch statement that utilizes instanceof, didn't find anything. > Instead of running a single thread that goes to sleep, maybe consider > using a ScheduledExecutorService with a simpler runnable object that > just logs the status a single time. Sounds like a good idea. That I have absolutely no idea how to implement. I used the hammer I know. :) > Don't forget to terminate the thread (or ExecutorService) when the > application is shutting-down, of you'll have a ClassLoader (and a a > huge memory) leak. I did think about that, but I wasn't sure how to detect a shutdown. Is there something available that handles it easily and reliably with only a small code change? Just now, I found the following page when I went looking for how to detect that (independent of the JVM shutting down): http://www.deadcoderising.com/execute-code-on-webapp-startup-and-shutdown-using-servletcontextlistener/ I think I could use this to create the thread on application startup as well as making sure it shuts down cleanly. It would mean that I can just create a new class for one of our applications and edit a config file, instead of monkeying with other people's code. It's very encouraging to me that you picked up on the lack of shutdown handling. It means I've got more than a sliver of your attention! Thanks, Shawn --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org