javaconnectionpool

Creation of url connection pool in java


I have some code like this in a method :

        URL url = new URL(endPoint);
        String encoding = Base64.encodeBase64String(this.key.getBytes());

        connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("POST");
        connection.setDoOutput(true);
        connection.setRequestProperty  ("Authorization", "Basic " + encoding);

This method is called many times from the client side. I wish I could create a connection pool and reuse the same as needed.

Is it possible to do so in Java?

Thanks in advance


Solution

  • Pooling HTTP connection is similar to other pooling object.

    Basically :

    I don't advise you to re-code all pool management, but rather use existing librairies like Jakarta Commons-pool.

    Jakarta Commons-pool enable you :