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
Solved

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

Posted on 2004-10-18
11
451 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

 
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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
Display the newly inserted values 3 81
java cyclic graphs 15 212
ejb on wildfly 5 30
java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: NO) 1 35
This article describes how to reset your Windows 10 password when you've forgotten it.
Many businesses neglect disaster recovery and treat it as an after-thought. I can tell you first hand that data will be lost, hard drives die, servers will be hacked, and careless (or malicious) employees can ruin your data.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

856 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