Visit the Below Website to access unlimited exam questions for all IT vendors and Get Oracle Certifications for FREE
http://www.free-online-exams.com
http://www.free-online-exams.com
Problem: How To
Monitor A Connection Pool Within OC4J 10.1.3.x
Remotely
This document is intended for
OracleAS 10.1.3.x administrators and J2EE developers deploying applications for
OracleAS 10.1.3.x who wish to monitor a Connection Pool to determine it's
current statistics using an MBean. This utility can effectively monitor a pool
to ensure connections are being released and what would be the ideal connection
pool maximum number of connections required as it monitors the connection pool
while in use.
In order to run this utility it is
vital you have access to the client side libraries required for remote access to
an OC4J instance whether it's an OPMN Managed OC4J or a stand alone OC4J
instance.
See Note 413342.1 for how to setup/install client side libraries.
The current version at the time this article was 10.1.3.3 and it can be downloaded from here.
http://download.oracle.com/otn/java/oc4j/101330/oc4j_admin_client_101330.zip
If running from the server or where a stand alone OC4J exists then there is no need to download the OAS client side distribution as the required JAR files already exist in that case.
Caution
This sample code is provided for educational purposes only and not supported by Oracle Support Services. It has been tested internally, however, and works as documented. We do not guarantee that it will work for you, so be sure to test it in your environment before relying on it.
See Note 413342.1 for how to setup/install client side libraries.
The current version at the time this article was 10.1.3.3 and it can be downloaded from here.
http://download.oracle.com/otn/java/oc4j/101330/oc4j_admin_client_101330.zip
If running from the server or where a stand alone OC4J exists then there is no need to download the OAS client side distribution as the required JAR files already exist in that case.
Caution
This sample code is provided for educational purposes only and not supported by Oracle Support Services. It has been tested internally, however, and works as documented. We do not guarantee that it will work for you, so be sure to test it in your environment before relying on it.
- Download the following
ZIP and extract in into a directory.
MonitorConnectionPool.zip - Update the build.properties to match your environment details, each property is explained in the file. An example is shown below.
# oracle.home
#
# This property is only required if using ANT to run this demo. It will
# use the property to build a classpath to enable the java code to
# compile/run
oracle.home=D:\\jdev\\oas-admin-distribution\\10133
#
# username
#
# OC4J administrator username
username=oc4jadmin
#
# password
#
# OC4J administrator password
password=welcome1
#
# serviceurl
#
# Can use stand alone OC4J or OPMN Managed OC4J instance
#
# STAND ALONE format
# service:jmx:rmi://<hostname>:<rmiport>
#
# OPMN Managed format
# service:jmx:rmi:///opmn://<hostname>:<opmn-port>/<container-name>
#
serviceurl=service:jmx:rmi:///opmn://myserver.site.com:6007/home
#
# This property is only required if using ANT to run this demo. It will
# use the property to build a classpath to enable the java code to
# compile/run
oracle.home=D:\\jdev\\oas-admin-distribution\\10133
#
# username
#
# OC4J administrator username
username=oc4jadmin
#
# password
#
# OC4J administrator password
password=welcome1
#
# serviceurl
#
# Can use stand alone OC4J or OPMN Managed OC4J instance
#
# STAND ALONE format
# service:jmx:rmi://<hostname>:<rmiport>
#
# OPMN Managed format
# service:jmx:rmi:///opmn://<hostname>:<opmn-port>/<container-name>
#
serviceurl=service:jmx:rmi:///opmn://myserver.site.com:6007/home
- Update the pool.properties to match your environment details, each property is explained in the file. An example is shown below. The applicationName is the name of the application where the data source was created in. If you have created the data source at the container level ($OH/j2ee/{container-name}/config) then the applicationName would be "default", if not the applicationName would be the name of the application which contains the data source. It's easiest to use ASC to verify a data source connectionPoolName and applicationName.
# obtain stats every 60
seconds
period=60
# connection pool name
connectionPoolName=Example Connection Pool
# application name where connection pool created in
applicationName=default
period=60
# connection pool name
connectionPoolName=Example Connection Pool
# application name where connection pool created in
applicationName=default
- Ensure OC4J is up and running before moving onto the "Run" section below.
Note: This application is tested with JDK 1.5 so
please use JDK 1.5 to compile/run this demo.
Option 1 Using ANT
Execute "ant run" to build, package and run the example.
Example output.
D:\jdev\ant-demos\1013\MonitorConnectionPool>ant run
Buildfile: build.xml
init:
[mkdir] Created dir: D:\jdev\ant-demos\1013\MonitorConnectionPool\lib
[mkdir] Created dir: D:\jdev\ant-demos\1013\MonitorConnectionPool\classes
compile:
[javac] Compiling 3 source files to D:\jdev\ant-demos\1013\MonitorConnectionPool\classes
[javac] Note: D:\jdev\ant-demos\1013\MonitorConnectionPool\src\oracle\support\oc4j\standalone\OC4JCon
ed or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
package:
[jar] Building jar: D:\jdev\ant-demos\1013\MonitorConnectionPool\lib\monitorconnectionpool.jar
run:
[echo] Running as oc4jadmin/***** to service:jmx:rmi:///opmn://myserver.site.com:6007/home
[java] 13/05/2008 14:58:36 oracle.support.oc4j.standalone.OC4JConnection <init>
[java] INFO: Username = oc4jadmin
[java] 13/05/2008 14:58:36 oracle.support.oc4j.standalone.OC4JConnection <init>
[java] INFO: Service URL = service:jmx:rmi:///opmn://myserver.site.com:6007/home
[java] 13/05/2008 14:58:38 oracle.support.oc4j.standalone.OC4JConnection <init>
[java] INFO: Connected to OC4J
[java] Monitor Connection Pool
[java] Pool Name : Example Connection Pool
[java] Application Name : default
[java] ** Started [13/05/08 14:58] with 60(sec) interval **
[java] --> Current Statistics [13/05/08 14:58]
[java] CreateCount: 7
[java] CloseCount: 7
[java] PoolSize: 0
[java] FreePoolSize: 0
[java] <--
[java] --> Current Statistics [13/05/08 14:59]
[java] CreateCount: 7
[java] CloseCount: 7
[java] PoolSize: 0
[java] FreePoolSize: 0
[java] <--
[java] --> Current Statistics [13/05/08 15:00]
[java] CreateCount: 8
[java] CloseCount: 7
[java] PoolSize: 1
[java] FreePoolSize: 1
[java] <--
Terminate batch job (Y/N)? y
D:\jdev\ant-demos\1013\MonitorConnectionPool>
Buildfile: build.xml
init:
[mkdir] Created dir: D:\jdev\ant-demos\1013\MonitorConnectionPool\lib
[mkdir] Created dir: D:\jdev\ant-demos\1013\MonitorConnectionPool\classes
compile:
[javac] Compiling 3 source files to D:\jdev\ant-demos\1013\MonitorConnectionPool\classes
[javac] Note: D:\jdev\ant-demos\1013\MonitorConnectionPool\src\oracle\support\oc4j\standalone\OC4JCon
ed or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
package:
[jar] Building jar: D:\jdev\ant-demos\1013\MonitorConnectionPool\lib\monitorconnectionpool.jar
run:
[echo] Running as oc4jadmin/***** to service:jmx:rmi:///opmn://myserver.site.com:6007/home
[java] 13/05/2008 14:58:36 oracle.support.oc4j.standalone.OC4JConnection <init>
[java] INFO: Username = oc4jadmin
[java] 13/05/2008 14:58:36 oracle.support.oc4j.standalone.OC4JConnection <init>
[java] INFO: Service URL = service:jmx:rmi:///opmn://myserver.site.com:6007/home
[java] 13/05/2008 14:58:38 oracle.support.oc4j.standalone.OC4JConnection <init>
[java] INFO: Connected to OC4J
[java] Monitor Connection Pool
[java] Pool Name : Example Connection Pool
[java] Application Name : default
[java] ** Started [13/05/08 14:58] with 60(sec) interval **
[java] --> Current Statistics [13/05/08 14:58]
[java] CreateCount: 7
[java] CloseCount: 7
[java] PoolSize: 0
[java] FreePoolSize: 0
[java] <--
[java] --> Current Statistics [13/05/08 14:59]
[java] CreateCount: 7
[java] CloseCount: 7
[java] PoolSize: 0
[java] FreePoolSize: 0
[java] <--
[java] --> Current Statistics [13/05/08 15:00]
[java] CreateCount: 8
[java] CloseCount: 7
[java] PoolSize: 1
[java] FreePoolSize: 1
[java] <--
Terminate batch job (Y/N)? y
D:\jdev\ant-demos\1013\MonitorConnectionPool>
Option 2 Using Java
To run the example outside of Ant, execute it like this.
- Ensure you have an ORACLE_HOME environment variable set in this example below we set it to our OracleAS client side distribution as shown below. This is a windows example.
set
ORACLE_HOME=D:\jdev\oas-admin-distribution\10133
- Run ant package as shown below to create the JAR file we will add to the classpath.
D:\jdev\ant-demos\1013\MonitorConnectionPool>ant package
Buildfile: build.xml
init:
[mkdir] Created dir: D:\jdev\ant-demos\1013\MonitorConnectionPool\lib
[mkdir] Created dir: D:\jdev\ant-demos\1013\MonitorConnectionPool\classes
compile:
[javac] Compiling 3 source files to D:\jdev\ant-demos\1013\MonitorConnectionPool\classes
[javac] Note: D:\jdev\ant-demos\1013\MonitorConnectionPool\src\oracle\support\oc4j\standalone\OC4JConnection.java uses uncheck
ed or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
package:
[jar] Building jar: D:\jdev\ant-demos\1013\MonitorConnectionPool\lib\monitorconnectionpool.jar
BUILD SUCCESSFUL
Total time: 2 seconds
D:\jdev\ant-demos\1013\MonitorConnectionPool>
Buildfile: build.xml
init:
[mkdir] Created dir: D:\jdev\ant-demos\1013\MonitorConnectionPool\lib
[mkdir] Created dir: D:\jdev\ant-demos\1013\MonitorConnectionPool\classes
compile:
[javac] Compiling 3 source files to D:\jdev\ant-demos\1013\MonitorConnectionPool\classes
[javac] Note: D:\jdev\ant-demos\1013\MonitorConnectionPool\src\oracle\support\oc4j\standalone\OC4JConnection.java uses uncheck
ed or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
package:
[jar] Building jar: D:\jdev\ant-demos\1013\MonitorConnectionPool\lib\monitorconnectionpool.jar
BUILD SUCCESSFUL
Total time: 2 seconds
D:\jdev\ant-demos\1013\MonitorConnectionPool>
- Now run as
follows.
java -classpath lib/monitorconnectionpool.jar;%ORACLE_HOME%/j2ee/home/admin_client.jar oracle.support.oc4j.standalone.PeriodicConnectionPoolStats
Output as follows:
D:\jdev\ant-demos\1013\MonitorConnectionPool>java
-classpath
lib/monitorconnectionpool.jar;%ORACLE_HOME%/j2ee/home/admin_client.ja
r oracle.support.oc4j.standalone.PeriodicConnectionPoolStats
13/05/2008 15:10:41 oracle.support.oc4j.standalone.OC4JConnection <init>
INFO: Username = oc4jadmin
13/05/2008 15:10:41 oracle.support.oc4j.standalone.OC4JConnection <init>
INFO: Service URL = service:jmx:rmi:///opmn://myserver.site.com:6007/home
13/05/2008 15:10:43 oracle.support.oc4j.standalone.OC4JConnection <init>
INFO: Connected to OC4J
Monitor Connection Pool
Pool Name : Example Connection Pool
Application Name : default
** Started [13/05/08 15:10] with 60(sec) interval **
--> Current Statistics [13/05/08 15:10]
CreateCount: 9
CloseCount: 8
PoolSize: 1
FreePoolSize: 1
<--
D:\jdev\ant-demos\1013\MonitorConnectionPool>
r oracle.support.oc4j.standalone.PeriodicConnectionPoolStats
13/05/2008 15:10:41 oracle.support.oc4j.standalone.OC4JConnection <init>
INFO: Username = oc4jadmin
13/05/2008 15:10:41 oracle.support.oc4j.standalone.OC4JConnection <init>
INFO: Service URL = service:jmx:rmi:///opmn://myserver.site.com:6007/home
13/05/2008 15:10:43 oracle.support.oc4j.standalone.OC4JConnection <init>
INFO: Connected to OC4J
Monitor Connection Pool
Pool Name : Example Connection Pool
Application Name : default
** Started [13/05/08 15:10] with 60(sec) interval **
--> Current Statistics [13/05/08 15:10]
CreateCount: 9
CloseCount: 8
PoolSize: 1
FreePoolSize: 1
<--
D:\jdev\ant-demos\1013\MonitorConnectionPool>
- At the time of this article the latest OracleAS 10.1.3.x patch set was 10.1.3.3. You should always be on the latest patchset to ensure any data source bugs that previously existed are fixed. See Note 397022.1 for more details on how to apply the OracleAS 10.1.3.3 patchset.
- If you are not using a framework such as ADF or Spring for example and are responsible for obtaining / releasing a Connection object in your code ensure you are closing the Connection object in a finally clause as shown in Note 402480.1.
- If you believe you have
a connection leak Note
395670.1 will enable you to turn on extra debugging on the data source to
confirm that.
Along with running this utility you should be able to determine if you have a data source connection leak issue and how to identify that and solve the issue.
For more information about MBeans and OC4J please see Note 554535.1
References:
Note 567784.1 - How To Monitor A Connection Pool
Within OC4J 10.1.3.x Remotely
No comments:
Post a Comment