114 lines
7.9 KiB
HTML
114 lines
7.9 KiB
HTML
|
<?xml version="1.0" encoding="UTF-8"?>
|
||
|
<!DOCTYPE html
|
||
|
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||
|
<html lang="en-us" xml:lang="en-us">
|
||
|
<head>
|
||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||
|
<meta name="security" content="public" />
|
||
|
<meta name="Robots" content="index,follow" />
|
||
|
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
|
||
|
<meta name="DC.Type" content="concept" />
|
||
|
<meta name="DC.Title" content="Use DataSource support for object pooling" />
|
||
|
<meta name="abstract" content="You can use DataSources to have multiple applications share a common configuration for accessing a database. This is accomplished by having each application reference the same DataSource name." />
|
||
|
<meta name="description" content="You can use DataSources to have multiple applications share a common configuration for accessing a database. This is accomplished by having each application reference the same DataSource name." />
|
||
|
<meta name="DC.Relation" scheme="URI" content="jdbcpool.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="poolprop.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="poolstat.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="poolnods.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="connectionpoolingsetup.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="connectionpoolingtest.htm" />
|
||
|
<meta name="copyright" content="(C) Copyright IBM Corporation 2006" />
|
||
|
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 2006" />
|
||
|
<meta name="DC.Format" content="XHTML" />
|
||
|
<meta name="DC.Identifier" content="poolwdts" />
|
||
|
<meta name="DC.Language" content="en-us" />
|
||
|
<!-- All rights reserved. Licensed Materials Property of IBM -->
|
||
|
<!-- US Government Users Restricted Rights -->
|
||
|
<!-- Use, duplication or disclosure restricted by -->
|
||
|
<!-- GSA ADP Schedule Contract with IBM Corp. -->
|
||
|
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
|
||
|
<link rel="stylesheet" type="text/css" href="./ic.css" />
|
||
|
<title>Use DataSource support for object pooling</title>
|
||
|
</head>
|
||
|
<body id="poolwdts"><a name="poolwdts"><!-- --></a>
|
||
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
||
|
<h1 class="topictitle1">Use DataSource support for object pooling</h1>
|
||
|
<div><p>You can use DataSources to have multiple applications share a common
|
||
|
configuration for accessing a database. This is accomplished by having each
|
||
|
application reference the same DataSource name.</p>
|
||
|
<p>By using DataSources, many applications can be changed from a central location.
|
||
|
For example, if you change the name of a default library used by all your
|
||
|
applications and you have used a single DataSource to obtain connections for
|
||
|
all of them, you can update the name of the collection in that DataSource.
|
||
|
All of your applications then start using the new default library.</p>
|
||
|
<p>When using DataSources to obtain connections for an application, you can
|
||
|
use the native JDBC driver's built-in support for connection pooling. This
|
||
|
support is provided as an implementation of the ConnectionPoolDataSource interface.</p>
|
||
|
<p>Pooling is accomplished by handing out "logical" Connection objects instead
|
||
|
of physical Connection objects. A <strong>logical Connection object</strong> is a connection
|
||
|
object that is returned by a pooled Connection object. Each logical connection
|
||
|
object acts as a temporary handle to the physical connection represented by
|
||
|
the pooled connection object. To the application, when the Connection object
|
||
|
is returned, there is no noticeable difference between the two. The subtle
|
||
|
difference comes when you call the close method on the Connection object.
|
||
|
This call invalidates the logical connection and returns the physical connection
|
||
|
to the pool where another application is able to use the physical connection.
|
||
|
This technique lets many logical connection objects reuse a single physical
|
||
|
connection.</p>
|
||
|
<div class="section"><h4 class="sectiontitle">Set up connection pooling</h4><p>Connection pooling is
|
||
|
accomplished by creating a DataSource object that references a ConnectionPoolDataSource
|
||
|
object. ConnectionPoolDataSource objects have properties that can be set for
|
||
|
handling various aspects of pool maintenance.</p>
|
||
|
<p>Refer to the example on
|
||
|
how to <a href="connectionpoolingsetup.htm">set up connection pooling</a> with
|
||
|
UDBDataSource and UDBConnectionPoolDataSource more details. You can also see
|
||
|
the <a href="jndi.htm">Java™ Naming and Directory Interface (JNDI)</a> for
|
||
|
details about the role JNDI plays in this example.</p>
|
||
|
<p>From the example,
|
||
|
the link that binds the two DataSource objects together is the dataSourceName.
|
||
|
The link tells the DataSource object to defer establishing connections to
|
||
|
the ConnectionPoolDataSource object that manages pooling automatically.</p>
|
||
|
</div>
|
||
|
<div class="section"><h4 class="sectiontitle">Pooling and non-pooling applications</h4><p>There is no
|
||
|
difference between an application that uses Connection pooling and one that
|
||
|
does not. Therefore, pooling support can be added after the application code
|
||
|
is complete, without making any changes to the application code.</p>
|
||
|
<p>Refer
|
||
|
to <a href="connectionpoolingtest.htm">Example: Test the performance of
|
||
|
connection pooling</a> for more details.</p>
|
||
|
<p>The following is output
|
||
|
from running the previous program locally during development.</p>
|
||
|
<p>Start
|
||
|
timing the non-pooling DataSource version... Time spent: 6410</p>
|
||
|
<p>Start
|
||
|
timing the pooling version... Time spent: 282</p>
|
||
|
<p>Java program
|
||
|
completed.</p>
|
||
|
<p>By default, a UDBConnectionPoolDataSource pools a single
|
||
|
connection. If an application needs a connection several times and only needs
|
||
|
one connection at a time, using UDBConnectionPoolDataSource is a perfect solution.
|
||
|
If you need many simultaneous connections, you must <a href="poolprop.htm">configure
|
||
|
your ConnectionPoolDataSource</a> to match your needs and resources. </p>
|
||
|
</div>
|
||
|
</div>
|
||
|
<div>
|
||
|
<ul class="ullinks">
|
||
|
<li class="ulchildlink"><strong><a href="connectionpoolingsetup.htm">Example: Set up connection pooling with UDBDataSource and UDBConnectionPoolDataSource</a></strong><br />
|
||
|
This is an example of how to use connection pooling with UDBDataSource and UDBConnectionPoolDataSource.</li>
|
||
|
<li class="ulchildlink"><strong><a href="connectionpoolingtest.htm">Example: Test the performance of connection pooling</a></strong><br />
|
||
|
This is an example of how to test the performance of the pooling example against the performance of the non-pooling example.</li>
|
||
|
</ul>
|
||
|
|
||
|
<div class="familylinks">
|
||
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="jdbcpool.htm" title="Object pooling is the most common topic to come up when discussing Java Database Connectivity (JDBC) and performance. Since many objects used in JDBC are expensive to create such as Connection, Statement, and ResultSet objects, significant performance benefits can be achieved by reusing these objects instead of creating every time you need them.">JDBC object pooling</a></div>
|
||
|
</div>
|
||
|
<div class="relconcepts"><strong>Related concepts</strong><br />
|
||
|
<div><a href="poolstat.htm" title="The maxStatements property, available on the UDBConnectionPoolDataSource interface, allows for statement pooling within the connection pool. Statement pooling only has an effect on PreparedStatements and CallableStatements. Statement objects are not pooled.">DataSource-based statement pooling</a></div>
|
||
|
<div><a href="poolnods.htm" title="You can develop your own connection and statement pooling without requiring support for DataSources or relying on another product.">Build your own connection pooling</a></div>
|
||
|
</div>
|
||
|
<div class="relref"><strong>Related reference</strong><br />
|
||
|
<div><a href="poolprop.htm" title="You can configure the ConnectionPoolDataSource interface by using the set of properties that it provides.">ConnectionPoolDataSource properties</a></div>
|
||
|
</div>
|
||
|
</div>
|
||
|
</body>
|
||
|
</html>
|