Software object pooling is not a new concept. There are invalid
Scenarios where some type of object pooling technique is employed
Improve application performance, concurrency, and scalability. After
All, having your database Code create a new
Connection
Object on every client request is an expensive process. Moreover,
Today's demanding applications, creating new connections for Data
Access from scratch, maintaining them, and tearing down the open
Connection can lead to massive load on the server.
We can configure a maximum number of DB connections in the pool.
Make sure you choose a maximum connection count large enough to handle
All of your database connections -- Alternatively, you can set0
For no limit. Further, we can set the maximum number of idle Database
Connections to be retained in the pool. Set this value-1
For no limit. The most optimal performance is attained when the pool in
Its steady state contains just enough connections to service all
Concurrent connection requests, without having to create new physical
Database connections at runtime. We can also specify the maximum time
(In milliseconds) to wait for a database connection to become
Available, which in this example is 10 seconds. An exception is thrown
If this timeout is exceeded. You can set this value-1
To wait indefinitely. Please make sure your connector driver, suchMySQL. Jar, Is placed inside/Common/libDirectory of your tomcat installation.
To achieve performance and high throughput, we also need
Fine-tune the container to work under heavy traffic. Here's how we'll
ConfigureConnector
Element formaxProcessors
AndacceptCount
Parameters inServer. xmlFile:
<!-- Configuring the request and response endpoints -->
<Connector port="80" maxHttpHeaderSize="8192" maxProcessors="150"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="150"
connectionTimeout="20000" disableUploadTimeout="true" />
Using ing JNDI reference
In order for JNDI to resolve the reference, we have to insert<resource-ref>
Tag intoWeb. xmlDeployment descriptor file. We first begin by setting<listener>
Tag for registeringServletContextListener
As shown below:
<listener>
<listener-class> com.onjava.dbcp.DBCPoolingListener</listener-class>
</listener>
<!-- This component has a dependency on an external resource-->
<resource-ref>
<description> DB Connection Pooling</description>
<res-ref-name> jdbc/TestDB</res-ref-name>
<res-type> javax.sql.DataSource</res-type>
<res-auth> Container</res-auth>
</resource-ref>
<servlet>
<servlet-name> EnrolledStudents</servlet-name>
<servlet-class> com.onjava.dbcp.CourseEnrollmentServlet</servlet-class>
<load-on-startup> 1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name> EnrolledStudents</servlet-name>
<url-pattern> /enrollment.do</url-pattern>
</servlet-mapping>
This binding is vendor-specific, and every container has its own
Mechanic for setting data sources. Please note that this is just
Declaration for dependency on an external resource, and doesn't create
The actual resource. comprehening the tags is pretty straightforward:
This indicates to the container that the local reference nameJDBC/testdbShocould be set by the app deployer, and this shoshould match with the Resource Name, as declared inServer. xmlFile.
I plan to translate this article another day and leave a mark first.