Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8605627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:53:03+00:00 2026-06-12T02:53:03+00:00

I’ve got a Runnable which gets a connection from a connection pool as below

  • 0

I’ve got a Runnable which gets a connection from a connection pool as below and has 60 seconds to do something with the connection:

private static ConnectionPoolDataSource cpds; // MysqlConnectionPoolDataSource

public void run(){
    while((System.currentTimeMillis()-created)<60000){
        try(Connection conn = cpds.getPooledConnection().getConnection()){  
            //do something
        }catch(SQLException sqle){}
    }
}

When the thread dies after 60s, i’ve assumed the connection is returned to the pool and when a new thread is created the connection can be re-used. But when I list my network connections, the list keeps growing as more threads are created. Are connections created as above being returned to the pool correctly and if so how can I force the connections to be re-used ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T02:53:05+00:00Added an answer on June 12, 2026 at 2:53 am

    You are not actually using a connection pool. A ConnectionPoolDataSource isn’t intended to be used directly. It is intended as a (special) DataSource for PooledConnection objects which are then kept in a connection pool by a (normal) DataSource implementation that provides connection pooling.

    A normal developer should not use a ConnectionPoolDataSource directly, it is intended for use with connection pools provided by Application Servers, or to be wrapped into general purpose DataSources that provide connection pooling.

    When a Connection is requested from the connection pool, it will checkout an existing PooledConnection (or request a new one from its ConnectionPoolDataSource), retrieve a Connection and return that to the user. When the user closes the Connection, the PooledConnection will signal the connection pool that it is available again.

    In this case you are creating a PooledConnection, retrieving a Connection from it and then discarding the PooledConnection. This means that the PooledConnection gets abandoned, and its physical connection to the database cannot be reused and will be closed/discarded when it is finally garbage collected (normally when the connection pool wants to close the physical connection, it will call close() on the PooledConnection).

    You either need to use connection pooling as provided by your Application Server, or use a general purpose connection pool like DBCP, c3p0 or HikariCP.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an array which has BIG numbers and small numbers in it. I
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.