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
最满意答案
您需要使用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)); }
相关问答
更多-
请参阅https://azure.microsoft.com/en-us/blog/announcing-powershell-script-support-azure-automation-2/ : 现在,您只能从PowerShell Runbook调用内联PowerShell Runbook,并从PowerShell Workflow或Graph Runbook调用PowerShell Workflow或Graph Runbook。 这可能在将来发生变化。 它还没改变:) Please see http ...
-
运行和管理python脚本(Run and managment python script)[2022-08-03]
检查子进程和多处理模块。 第一个允许您执行外部应用程序。 要使用第二个,您将需要调用一些python代码,但管理功能应该更广泛。 Check subprocess and multiprocessing modules. The first one allows you to execute external application. To use the second one, you'll be required to call some python code, but the management ... -
您需要使用automationManagementClient.Jobs.Create public static JobCreateResponse Create( this IJobOperations operations, string resourceGroupName, string automationAccount, JobCreateParameters parameters ) 你可以在这里找到一个完整的样本,这将是相关的部分 - private voi ...
-
让我们以反向年表的方式来看待这个: 这两种方法怎么样? 通过“ 不使用运行空间”运行powershell代码是没有的 。 简单的解释是,运行空间是核心先决条件 - 顾名思义, 运行 空间是PowerShell代码运行的空间 。 当你这样做时: PowerShell powerShell = PowerShell.Create() 隐式创建运行空间并将其附加到PowerShell实例。 唯一的区别是您只需将对Runspace创建的控制推迟到System.Management.Automation API,而 ...
-
您正在从$ SqlCredential获取用户名和密码,但您将凭证存储在$ cred变量中。 这些变量必须相同。 还要确保在Azure自动化帐户中创建自动化凭证对象,其名称与“SqlAdminUser”同名 In the end I created hybrid workers which allowed me to install the latest version of the ADAL SQL library, which supports Azure AD authentication.
-
如何使用资源管理器模块使用Azure自动化停止所有VM?(How to stop all VMs with Azure Automation using Resource Manager module?)[2021-12-11]
根据我的理解,ASM模式是默认的。 如果您要使用ARM命令,首先需要使用Switch-AzureMode切换模式 另一个困惑是Get-AzureRMVM命令的目的是什么。 我用Google搜索但却找不到任何东西 - Below is the solution $cred = Get-AutomationPSCredential -Name 'Cred' Add-AzureRmAccount -Credential $cred Select-AzureRmSubscription -Name 'Subscr ... -
无法在Azure Automation混合工作程序上运行远程会话(Cannot run remote session on Azure Automation hybrid worker)[2022-06-07]
为后代回答我自己的问题。 将Hybrid Worker Group更改为使用机器管理员凭据运行允许设置工作; 使用“默认”凭据(我相信的系统帐户)没有。 我认为在Windows中,系统帐户不允许连接到其他机器/服务,所以这可能是原因,但我猜是在那里。 Answering my own question for posterity. Altering the Hybrid Worker Group to run using credentials for a machine admin allowed the ... -
在Azure自动化中似乎存在一个范围问题,在处理程序内部调用Write-Output或Write-Host 。 将消息设置为处理程序中的全局变量,然后在ExecuteNonQuery之后调用Write-Output为我的目的工作。 Write-Output "Starting" $conn = New-Object System.Data.SqlClient.SqlConnection "Data Source=abc.database.windows.net,1433;Initial Catalog=d ...
-
我终于开始工作了! 问题出在运行测试的perl脚本中。 我没有使用system($ command),而是使用了back tick操作符。 我不知道为什么反引号运算符不会返回输出,也不知道为什么system()在这里工作。 I finally got it to work! The problem was in the perl script which was running the tests. Instead of using system($command), I was using back ti ...
-
如果您查看此作业的作业历史记录,是否列出了任何错误记录? 如果您只是尝试抓取所有虚拟机,它是否有效? $VMs = Get-AzureVM Write-Output $VMs 此外,我们建议在Azure自动化中使用OrgID auth,而不是使用证书身份验证。 有关详细信息,请参阅http://azure.microsoft.com/blog/2014/08/27/azure-automation-authenticating-to-azure-using-azure-active-directory/ ...