首页 \ 问答 \ Oracle JDBC Pool Connection访问分配策略?(Oracle JDBC Pool Connection access allocation strategy?)

Oracle JDBC Pool Connection访问分配策略?(Oracle JDBC Pool Connection access allocation strategy?)

使用Oracle JDBC连接池时,有没有办法控制连接的分配方式? 特别是,有没有办法指定使用LIFO策略? 似乎连接可能以循环方式发布。

在这种情况下:

  • 使用池中的最大连接数(10)
  • 此后,只使用一个并发连接,每5秒检索并返回一次
  • 不活动超时设置为60秒

如果使用循环策略,则10个池连接中的每一个将在60秒的时间段内使用。 当发生非活动超时检查时,每个连接都将在最后一分钟内处于活动状态,因此没有连接将成为要关闭的候选者。 连接池将保留10个连接,但实际上只需要1个连接。 至少这是我似乎正在经历的事情。 我希望游泳池缩小到只有1个连接。

我对驱动程序如何工作的理解是正确的吗? 有没有办法从池中控制连接分配策略(LIFO,FIFO,循环)或者我是否必须使用其他池化机制?

下面是一个测试(使用不推荐的apis)。 在这种情况下,创建了3个连接,它只会缩减到2而不是1。

编辑更密切地反映以上描述:

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) {}; }
            }
        }
    }

}

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) {}; }
            }
        }
    }

}

原文:https://stackoverflow.com/questions/8955974
更新时间:2023-08-13 15:08

最满意答案

您需要使用automationManagementClient.Jobs.Create

public static JobCreateResponse Create(
    this IJobOperations operations,
    string resourceGroupName,
    string automationAccount,
    JobCreateParameters parameters
)

你可以在这里找到一个完整的样本这将是相关的部分 -

private void JobStart_Click(object sender, RoutedEventArgs e)
 {
        // Check for runbook name
        if (String.IsNullOrWhiteSpace(RunbookName.Text) || String.IsNullOrWhiteSpace(PublishState.Text)) throw new ArgumentNullException(RunbookName.Text);

        // Create job create parameters
        var jcparam = new JobCreateParameters
        {
            Properties = new JobCreateProperties
            {
                Runbook = new RunbookAssociationProperty
                {
                    // associate the runbook name
                    Name = RunbookName.Text
                },

                // pass parameters to runbook if any
                Parameters = null
            }
        };

        // create runbook job. This gives back JobId
        var job = automationManagementClient.Jobs.Create(this.automationAccountName, jcparam).Job;

        JobGuid.Text = JobId.Text = job.Properties.JobId.ToString();

        Log.Text += (String.Format("\nJob Started for Runbook {0} , JobId {1}", RunbookName.Text, JobId.Text));
}

You need to use the automationManagementClient.Jobs.Create

public static JobCreateResponse Create(
    this IJobOperations operations,
    string resourceGroupName,
    string automationAccount,
    JobCreateParameters parameters
)

You can find a full sample here this would be the relevant part -

private void JobStart_Click(object sender, RoutedEventArgs e)
 {
        // Check for runbook name
        if (String.IsNullOrWhiteSpace(RunbookName.Text) || String.IsNullOrWhiteSpace(PublishState.Text)) throw new ArgumentNullException(RunbookName.Text);

        // Create job create parameters
        var jcparam = new JobCreateParameters
        {
            Properties = new JobCreateProperties
            {
                Runbook = new RunbookAssociationProperty
                {
                    // associate the runbook name
                    Name = RunbookName.Text
                },

                // pass parameters to runbook if any
                Parameters = null
            }
        };

        // create runbook job. This gives back JobId
        var job = automationManagementClient.Jobs.Create(this.automationAccountName, jcparam).Job;

        JobGuid.Text = JobId.Text = job.Properties.JobId.ToString();

        Log.Text += (String.Format("\nJob Started for Runbook {0} , JobId {1}", RunbookName.Text, JobId.Text));
}

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。