tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <christopher.d.schu...@comcast.net>
Subject Re: How can I count the number of active requests/servlets for Tomcat?
Date Thu, 15 Jan 2004 23:58:59 GMT
Tom,

> I'm running a web service using Axis with Tomcat.  How can I count 
> the number of active requests?

I think you want to use a Filter for your requests:

public class ConnectionCounter
	implements javax.servlet.Filter
{
	private int _activeConnections = 0;

	public void init(FilterConfig fc) { }
	public void destroy() { }
	public doFilter(ServletRequest req,
			ServletResponse rsp,
			FilterChain fc)
		throws ServletException, IOException
	{
		synchronized(this) {
			++_activeConnections;
		}

		fc.doFilter();

		synchronized(this) {
			--_activeConnections;
		}
	}

	public int getActiveConnectionCount()
	{
		// Need not be synchronized, int access is atomic
		return _activeConnections;
	}
}

Of course, you'll need to get a reference to your filter in order to
read the connection count, but that is an exercise left to the reader :)

> I used the HttpListener interace but the sessionDestroyed method
> doesn't seem to get called until 5 minutes after the servlet ends.

Ouch. You have web services that use sessions? You should probably turn 
off http sessions for those...

-chris


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message