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 7880183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:04:58+00:00 2026-06-03T04:04:58+00:00

I am writing a connection pool using Executors. My problem is that when the

  • 0

I am writing a connection pool using Executors. My problem is that when the database goes down, all the connections in pool become invalid connections.

One way would be to refresh the connection pool at a regular interval, or to check the validity of the connections. What is the best way to handle this type of problem?

  • 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-03T04:05:00+00:00Added an answer on June 3, 2026 at 4:05 am

    First of all, if you don’t absolutely, definitely, no way around, HAVE TO write your own, this is real typical case of reinventing a perfectly fine wheel. There are lots of fine and dandy connection pool implementations available on the interwebz.

    I (among many others) use Apache DBCP: http://commons.apache.org/dbcp/

    If you have some kind of uber-special database, you could at least rely on an existing pooling solution like Commons Pool: http://commons.apache.org/pool/

    You know, using apache stuff allows you to sit with the cool kids 😉

    Well then, if you really have to write your own I’d suggest this:

    Whenever a connection is requested, check it for validity. No way arround this. If it’s not valid anymore, either immediately drop all connections in the pool (assuming all of them are invalid), or just get the next one and just drop the one you checked. Repeat until you find a valid one or you have to grow the pool. Growing the pool will need to check for validity and abort if new connections can’t be established (obviously). You would have some fine infinity-looping on your hand otherwise.

    A secondary thread who checks on the pool and cleans it up and/or grows it as needed seems fine too. Just don’t rely on it alone as it may very well miss an invalid connection and you would still serve unusable pool elements.

    The thread (or threads) may only serve to speed things up (checking/growing the pool), but are not suited to do the job for themselves. You will have to check/grow on request, secondary threads only assist in avoiding that.

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

Sidebar

Related Questions

I'm writing a small (C#) client application that sends data using a TCP/IP connection
When I am writing connection pool to connect to database, I am always confused
I am writing a class that represents a pool of IPC connections that are
I'm writing a program to communicate with certain patient monitor using connection-less (UDP) sockets.
I am writing a code that reads data from a http connection and stores
I'm writing a GUI application that regularly retrieves data through a web connection. Since
I am writing a game server that requires connecting to a MySQL database server
I'm writing an Adhearsion component that uses ActiveRecord. The problem is that the component
I'm writing a C++ application. I realized that one of my worker threads may
We have an existing SQL database, and I'm writing a node.js server that accesses

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.