Solved

how can i get the active connection number in tomcat poll connection?

Posted on 2004-10-18
11
446 Views
Last Modified: 2010-04-01
in resin ,it will auto show the current active connection ,but in tomcat it can not show ,how can i know the active connection in tomcat!

 thanks!
0
Comment
Question by:hgbdelphi
  • 6
  • 5
11 Comments
 

Author Comment

by:hgbdelphi
Comment Utility
hi,experts,can help me again,thanks.
0
 

Author Comment

by:hgbdelphi
Comment Utility
experts help me.
0
 
LVL 21

Accepted Solution

by:
MogalManic earned 100 total points
Comment Utility
Create a session counter class that implements HTTPSessionListener.  Something like this:

public class SessionCounter implements HttpSessionListener
{
  int sessionCount=0;
  ServletContext=null;
public void sessionCreated(HttpSessionEvent event)
{
   sessionCount++;
   if (context==null)
     storeInContext(event)
}

public sessionDestroyed(HttpSessionEvent event)
{
  sessionCount--;
}

private storeInContext(HttpSessionEvent event)
{
  context=event.getSession.getServletContext();
  context.setAttribute("sessionCounter", this);
}

0
 
LVL 21

Expert Comment

by:MogalManic
Comment Utility
This solution will work in any J2EE complient servlet container
0
 

Author Comment

by:hgbdelphi
Comment Utility
to  MogalManic:
  thanks for your help,but i want to know the connection number in tomcat with database poll connection to sqlserver2000,how can i see the connection number???
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 21

Expert Comment

by:MogalManic
Comment Utility
I would stear clear of server specific functionality.  I'm sure there is a way to do what you want, but it would ONLY work in Tomcat.  If you switched to WebLogic, you would have to figure it out AGAIN.

The web Listener classes can notify you when settions are created/destroyed and attributes are added/removed.  Does each user create a session when they login?  If so then the session count is the usercount.

0
 

Author Comment

by:hgbdelphi
Comment Utility
hi MogzlManic
  say sorry for my poll english,i want see the ConnectionPool information like this,
[08:16:49.765]   getConnection()
[08:16:49.765]    Check for timeout, activeCount=1, useCount=0
[08:16:49.765]    Found available connection
[08:16:49.765]    Return allocated connection, activeCount=1, useCount=1
[08:16:50.328]   releaseConnection(), activeCount=1, useCount=0

this information will autoshow in resin,but not show in tomcat,i want to see the information in tomcat ,how can i do it??

thanks!
0
 
LVL 21

Expert Comment

by:MogalManic
Comment Utility
You are using the Tomcat Connection Pool?
0
 

Author Comment

by:hgbdelphi
Comment Utility
yes.
0
 
LVL 21

Expert Comment

by:MogalManic
Comment Utility
It might not be possible.  I have the source at work and I will try to find the source code for Tomcat's connection pool.  One possiblity is to wrap the connection pool around your interface (basicaly a Facade).  In your interface keep track of the statistics:
Class MyConnectionPool {
   private ? tomcatPool;
   Set activeSet=new HashSet();

   ....
   public Connection GetConnection(...)
  {
     useCount++;
     if (useCount>maxUseCount)
        maxUseCount=useCount;
     log.info("Pool Usage:"+useCount);
     Connection c=tomcatPool.getConnection(...);
     activeSet.put(new String(c.hashCode()); //Store Unique ID for each active Connection
     log.info("Active Count:"+activeSet.size());
     return c;
     
  }

  ...
  public Connection releaseConnection(...)
  {
      useCount--;
      tomcatPool.releaseConnection(...);
  }
0
 

Author Comment

by:hgbdelphi
Comment Utility
hi  MogalManic,
 thanks for your replay,can i get the connection number by another method and not only for tomcat connectionpoll sourcecode,like sqlserver2000 or some sql statement and another....

if i change the tomcat source code ,i think this is not some good idea.
thanks1
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
This article will show you how to create an ISO CD-ROM/DVD-ROM image (*.iso), and MD5 checksum signature, for use with VMware vSphere Hypervisor 6.5 (ESXi 6.5). It's a good idea to compare checksums, because many installations fail because of a corr…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now