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

The Archive Base Latest Questions

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

can you look at my connection pool if it is a possible way to

  • 0

can you look at my connection pool if it is a possible way to implement it?

public class ConnectionPool {
    private static List<DBConnection> pool = null;
    private static int available = 0;
    private ConnectionPool() {}

    public static DBConnection getConnection() {
        if (pool == null) {
             pool = new ArrayList<DBConnection>();
             for (int i = 0; i < 3; i++) {
                 try {
                    pool.add(new DBConnection());
                    available++;
                } catch (SQLException e) {
                    e.printStackTrace();
                }
             }
        }
        if (pool.size() > 0) {
            available--;
            return pool.remove(available);
        } else {
            return null;
        }
    }

    public static void returnConnection(DBConnection c) {
        pool.add(c);
        available++;
    }
}

I’m using only one array and the client should ask the connection pool for a connection use it and then return it to the connection pool.

  Connection connection = ConnectionPool.getConnection();
  connection.execute("insert into users values('"+user.getUsername()+"', '"+user.getPassword()+"', '"+user.getGroup()+"', '"+banned+"', '"+broker+admin+sharehodler+company+"')");      
  ConnectionPool.returnConnection(connection);
  connection = null;

Please I need feedback on this implementation. Thank you

  • 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-03T21:58:41+00:00Added an answer on June 3, 2026 at 9:58 pm

    There are some points that make this implementation very problematic.

    • Thread safety. What if several threads work with the pool? You are not locking the list on read/write access.
    • Static maximum pool size of 3 connections, also you immediately create all of them, whether they are needed or not. A common strategy is to create a bunch of connections and create some more when needed, until the allowed/configured maximum is reached.
    • You only have static methods. It should be possible to have several pools, meaning you need instances of ConnectionPool.
    • No way to pass host+dbname+user+password to the connections that are created.
    • You don’t deal with ‘broken’ connections – you may have to re-create a connection if an existing one screwed up. This is far more relevant than I thought before I started using pools.
    • Use config values instead of static values, see point #2
    • Lastly: sure, it’s interesting to write this stuff yourself – but if you need a pool for a project, pick an existing one, such as c3p0 or the tomcat connection pool.

    I’m sure there’s more to point out, but unless these are fixed, there’s no use in continuing.

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

Sidebar

Related Questions

In short, how can I restrict access to connection pool X based on application
I can look up the remote interface of an EJB3 from a Glassfish 2.1
Is there anyway I can look at the size of a file the application
This topic can look similar to others but I haven't found any usable answer
So far I know that FileSystemWatcher can look into a folder and if any
When I run the debugger I can look that ContextMenuInfo menuInfo variable from the
Are there any tools that can look at a database, and generate the basic
I need to sort an array that can look like this: $array[4][0] = array('id'
I have a loop that can look like this: For Each article In artAll
I have a webpage where users can look for clients and select them. After

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.