Solved

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

Posted on 2004-10-18
11
450 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 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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Can I clean log of  running tomcat 7 server ? 3 126
bean mapper frameworks 5 60
caughtSpeeding java challenge 16 137
Using Tomcat as raspberry pi java app server 13 166
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This article outlines why you need to choose a backup solution that protects your entire environment – including your VMware ESXi and Microsoft Hyper-V virtualization hosts – not just your virtual machines.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

809 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