Phani Kumar, January 10, 2017 - 3:59 pm UTC
Hello AskTom,
Thanks for the information which you given before on DRCP Connection Broker Info. It helped me a lot.
A Quick Question.....
(Java)Program:-
package com.pvc.spring.ucp.drcp;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
import oracle.ucp.jdbc.PoolDataSource;
import oracle.ucp.jdbc.PoolDataSourceFactory;
public class UcpWithDRCP {
/*
* The sample shows how to use DRCP with UCP. Make sure that correct
* connection URL is used and DRCP is enabled both on the server side and on
* the client side.
*/
static public void main(String args[]) throws SQLException {
PoolDataSource pds = PoolDataSourceFactory.getPoolDataSource();
pds.setConnectionFactoryClassName("oracle.jdbc.pool.OracleDataSource");
pds.setUser("sys as sysdba");
pds.setPassword("admin");
// Make sure that DRCP_URL has (SERVER=POOLED) specified
pds.setURL("jdbc:oracle:thin:@//localhost:1521/orcl:POOLED");
pds.setConnectionPoolName("DRCP_UCP_Pool");
// Set UCP Properties
pds.setInitialPoolSize(2);
pds.setMinPoolSize(4);
pds.setMaxPoolSize(10);
// DRCP
Properties prop = new Properties();
prop.put("oracle.jdbc.DRCPConnectionClass", "DRCP_UCP_Pool");
pds.setConnectionProperties(prop);
Connection conn = pds.getConnection();
// Get the Database Connection from Universal Connection Pool.
try (Connection conn1 = pds.getConnection()) {
System.out.println("\nConnection obtained from UniversalConnectionPool");
// Perform a database operation
doSQLWork(conn1);
System.out.println("Connection returned to the UniversalConnectionPool");
}
}
public static void doSQLWork(Connection connection) throws SQLException {
// Statement and ResultSet are auto-closable by this syntax
try (Statement statement = connection.createStatement()) {
try (ResultSet resultSet = statement.executeQuery("select SYSDATE from DUAL")) {
while (resultSet.next())
System.out.print("Today's date is " + resultSet.getString(1) + " ");
}
}
System.out.println("\n");
}
}
------------------------------------------------------------
when we run this program, we are getting following db info as follows...
SYS.DRCP_UCP_Pool-> 2(NUM_REQ) 0(NUM_HITS) 2(NUM_MISSES) 0(NUM_WAITS) 0(WAIT_TIME) 0(CLIENT_REQ_TIMEOUTS) 1(NUM_AUTHENTICATIONS) 0(CON_ID).
when we observe this data, we identified the issue like NUM_HITS = 0 and NUM_MISSES> 0.
That looks strange, we have just created 2 connections and none of them had been reused.
I am not understanding , why it is behaving like this.
Could you please help me on this and last thing i just want to know that the following..
Is we can create a different connection brokers for different microservices..?
Thank you,
Phani Kumar.