1

I have a few questions about JDBC connections.

  • Is there any way of seeing the used JDBC connection?
  • If I limit the JDBC connection to 100 for example, if I reach the top of used jbdc connection, how can I free them without restarting the server?

Thanks

user2091010
  • 85
  • 1
  • 2
  • 7

2 Answers2

0
  1. It depends on the pool/server. But this is a very fluctuent information. connections are typically retrieved from a pool for the duration of a transaction (a few milliseconds), and then added back to the pool. And on a typical enterprise application, there are many many transactions every second. So, at the time you're looking at the connections, the number of used connections has already changed.

  2. If you mean that you would like to close connections that have been unused for a given time (i.e. shrink the size of the pool), then, once again, this is a configuration that depends on the pool you're using. Most of them allow doing that. Read your pool documentation.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • @user2091010 what is your question exactly? What would you like us to tell you? All we know is that you're using an unknown pool, in an unknown server, and have tried shrinking it without knowing how, and saw that connections weren't closed but without explanation of how you concluded that. – JB Nizet Oct 06 '14 at 18:09
0

If you are using DBCP2, then you can print the active connections which are not closed. Here the class is extending BasicDataSource, and overriding getConnection method.

try {String className = Thread.currentThread().getStackTrace()[2].getClassName();
        LOG.info("For class :: " + className + " || " + "max total connections :: " + super.getMaxTotal()+ " || "   +"  Active Connections count :: "+ super.getNumActive());

        connection = super.getConnection();

    }catch (SQLException e) {
        LOG.error("SQL Exception in Connection", e);
    }
CodeRider
  • 564
  • 4
  • 15