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

  • Home
  • SEARCH
  • 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 7247923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:04:13+00:00 2026-05-28T22:04:13+00:00

When using an Oracle JDBC connection pool, is there a way to control how

  • 0

When using an Oracle JDBC connection pool, is there a way to control how the connections are handed out? In particular, is there a way to specify using a LIFO strategy? It seems the connections may be handed out in a round robin fashion.

In this scenario:

  • max connections in pool are used (10)
  • thereafter, only one concurrent connection is ever used, every 5 sec retrieved and returned
  • inactivity timeout is set to 60 sec

if a round robin strategy is used, each of the 10 pooled connections will be used within a 60 sec time period. When the inactivity timeout check occurs, every connection will have been active within the last minute, so no connection will be a candidate to be closed. The connection pool will remain with 10 connections, although in reality, only 1 is required. At least that is what I seem to be experiencing. I would like the pool to shrink down to only 1 connection.

Is my understanding of how the driver works correct? Is there a way to control the connection allocation strategy from the pool (LIFO, FIFO, round robin) or would I have to use other pooling mechanisms?

Below is a test (using deprecated apis). In this case, 3 connections were created, and it would only shrink back down to 2, not 1.

EDIT to more closely reflect above description:

import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import oracle.jdbc.pool.OracleDataSource;


public class Main {

    public static void main(String[] args) throws InterruptedException, IOException, ClassNotFoundException, SQLException {

        String url = "jdbc:oracle:thin:@//host:1521/SID";
        String user = "user";
        String pwd = "pwd";

        OracleDataSource ocpds;

        ArrayList<Connection> tempConnList = new ArrayList<>();


        try {

            ocpds = new OracleDataSource();
            ocpds.setURL(url);
            ocpds.setUser(user);
            ocpds.setPassword(pwd);

            java.util.Properties prop = new java.util.Properties();
            prop.setProperty("MinLimit", "1");
            prop.setProperty("MaxLimit", "10");

            prop.setProperty("InactivityTimeout", "60");    //  seconds
            prop.setProperty("AbandonedConnectionTimeout", "60");  //  seconds
            prop.setProperty("PropertyCheckInterval", "60"); // seconds            

            // set DataSource properties
            ocpds.setConnectionCachingEnabled(true);
            ocpds.setConnectionCacheProperties(prop);
            ocpds.setConnectionCacheName("TestCache");


            // Ramp up to max
            for (int i=0; i<10; i++) {
                Connection conn = ocpds.getConnection();
                tempConnList.add(conn);
            }

            // Release them all
            for (Connection conn : tempConnList) {
                conn.close();
            }


            // Grab and release one connection at a time
            for (int i = 0; i < 60; i++) {

                System.out.println(new java.util.Date());

                // Grab and release
                Connection conn = ocpds.getConnection();
                conn.close();

                try {
                    Thread.currentThread().sleep(5000);
                } catch (InterruptedException ie) {
                    System.err.println("error message: " + ie.getMessage());
                }

            }

        } catch (SQLException e) {
            System.err.println("error message: " + e.getMessage());
        } finally {
            for (Connection conn : tempConnList) {
                if (conn != null) { try { conn.close(); } catch (SQLException ignored) {}; }
            }
        }
    }

}
  • 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-05-28T22:04:14+00:00Added an answer on May 28, 2026 at 10:04 pm

    Oracle support has responded that a round robin method is used for feeding back the connections from the pool. In Oracle JDBC 12 (current version is 11.2.0.3), there will be a property, “UseLIFO”, which will allow “last in first out” retrieval:

    prop.setProperty("UseLIFO", "true");
    

    In the example posted in the question, this will let the idle time out to shrink the pool down to a single connection.

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

Sidebar

Related Questions

I'm using hibernate with connection pooled datasource <bean id=dataSource class=oracle.jdbc.pool.OracleDataSource destroy-method=close> <property name=connectionCachingEnabled value=true
I am using Oracle 9 JDBC Thin Driver - the connection string I have
We are currently using Spring JDBC with connection pool implementation from DBCP to connect
Using Spring 1.2.1 and oracle.jdbc.pool.OracleDataSource 10.2.0.3.0 I sometimes get a stack trace like below.
Is it possible to connect to an Oracle DB using a jdbc connection string
I am using Spring JdbcTemplate/SimpleJdbcTemplate in combination with an Oracle datasource (oracle.jdbc.pool.OracleDataSource) via JNDI
I'm investigating moving away from an Oracle connection pool and using the Tomcat connection
I am connecting to an oracle database using a connection pool. I have set
I am using Oracle 9 and JDBC and would like to encyrpt a clob
I am using weblogic JDBC datasource and my DB is Oracle 10g, below 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.