views:

262

answers:

3

I would like to get access to the Tomcat internal data from a servlet (or filter). In particular, I would like to read information about busy threads, from thread pool manager. So, my question is if it is possible at all (I can imagine that it could be blocked for safety reason)? If it's possible, maybe someone could give me any advice where to start (some entry point singleton, etc.)?

I know, that I could retrieve this information through the JMX. But I would rather prefer direct API (because the JMX is probably quite heavy, isn't it?).

+1  A: 

Would ServerFactory#getServer() help? It provides access to the Tomcat Server instance that the servlet/filter is running in. From there, you might be able to dig down to find the information you need/

To answer your question regarding JMX being "heavy": probably not. If you're just doing periodic monitoring of the data, you should be fine, especially if you're accessing the mbeans inside the same VM through the platform MBeanServer

Kevin
Thank you for your advice regarding the ServerFactory. This really seems to be a good starting point. I'll try to investigate this path.Regarding JMX: I would like to monitor thread pool usage, per each request, to apply some adaptational algorithm to the processing. So, I suspected that JMX introduce too big footprint. But if the ServerFactory attempt fails I will check this possibility as well.
oo_olo_oo
A: 

What exactly are you trying to accomplish? Lambda Probe is an excellent monitoring tool for Tomcat that might have what you're looking for.

sigget
Thanks, but I would like to monitor thread pool usage, per each request, to apply some adaptational algorithm to the processing. So, I need to do it in my servlet (or filter).
oo_olo_oo
A: 

After testing different approaches I eventually decided to use JMX. The overhead appeared to be less significant that I had expected.

oo_olo_oo