Solved

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

Posted on 2004-10-18
11
453 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 

Author Comment

by:hgbdelphi
ID: 12343311
hi,experts,can help me again,thanks.
0
 

Author Comment

by:hgbdelphi
ID: 12353275
experts help me.
0
 
LVL 21

Accepted Solution

by:
MogalManic earned 100 total points
ID: 12353768
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 21

Expert Comment

by:MogalManic
ID: 12353771
This solution will work in any J2EE complient servlet container
0
 

Author Comment

by:hgbdelphi
ID: 12355218
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
 
LVL 21

Expert Comment

by:MogalManic
ID: 12356570
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
ID: 12364906
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
ID: 12365060
You are using the Tomcat Connection Pool?
0
 

Author Comment

by:hgbdelphi
ID: 12365375
yes.
0
 
LVL 21

Expert Comment

by:MogalManic
ID: 12368072
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
ID: 12376514
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
jersey maven project error 7 145
Fisheye tool 2 121
Can't access image with tomcat/html 6 106
how to hide hide popup page refresh second time? 10 161
Facebook has became the #1 social media platform. People share many funny videos there, yet you don't know how to download them? Now you can download Videos from Facebook in just 3 simple steps.
Direct mail marketing is the act of mailing materials straight to prospective customers. This wide form of marketing is one of the oldest methods of communicating with a geographic based demographic. So is it useful in 2017 and beyond?
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

740 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