Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-10-18
11
Medium Priority
?
485 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
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 400 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
Technology Partners: 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

Industry Leaders: 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!

Question has a verified solution.

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

Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Integration Management Part 2
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

972 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