Logo of Bento frameworkspaceObject Oriented Programming


JBuilder 2007

PooledStatement

Free source code example for Bento framework...

Seeing is believing! First of all, please enjoy the example of Bento framework that is running on our web site. It is the simple photo Blog where you can upload the image files by your web browser (multipart/form-data), or e-mail with file attachment. After you grasp how it works, please explore its source code. The source code of the example is included in the FREE trial version of Bento framework.

[ Try and download example ... ]

Introduction ...

The main class of this API is PooledPS. PoolesPS caches the pairs of JDBC Connection and JDBC PreparedStatement in its pools. Because not every SQL database supports pre-compilation of SQL statement (for instance, the old version of MySQL database does not cache the pre-compiled SQL statement), the usage of JDBC PreparedStatement does not always result in the significant performance improvement. But, because the same SQL statement is called again and again on the typical online transaction system, the pooling mechanism can avoid the I/O overhead on opening new connections repeatedly.

Easy programming interface ...

PooledPS takes care of all the tasks related with JDBC Connection and JDBC PreparedStatement. And the source code of your Java program can be as simple as possible. Please click the link below and look into the source code example.

[ Source code example ... ]

How does it work?

Let's look into what's going on behind this API, following some very simple scenario. Assume that the maximum number of JDBC PreparedStatement per each SQL statement is set to 2, and the first thread (Thread1) is now going to request some JDBC PreparedStatement.

2 free PreparedStatement in the pool

If the 2 free JDBC PreparedStatement are available in the pool for the specified SQL statement at this time, one of them (the older one will be selected, i.e. by the first-in first-out rule) will be returned to the calling thread:

One of the 2 free PreparedStatement is returned

After that, the subsequent request for the same SQL statement is dispatched by the second thread (Thread2). At this time, another free instance of JDBC PreparedStatement is still available in the pool:

Another free PreparedStatement in the pool

So another one will be returned to the calling thread:

Another free PreparedStatement is returned

The pool for the specified SQL statement is now empty. If yet another request for the same SQL statement is dispatched by the third thread (Thread3) at this moment, no more instance of JDBC PreparedStatement will be created, because we set the maximum number per each SQL statement to 2. And the Thread3 will be suspended:

Empty pool

The Thread3 will stay suspended until one of JDBC PreparedStatement will be push back into the pool by the preceding thread. For example, if the Thread1 pushes it back to the pool, the Thread3 can take over it:

Push back

By this way, this API prevents the system resources to be exhausted.

Read Java doc / FREE Download

You can read the Java doc for this API online. Or it is included in the trial version of this API and you can download it at FREE.

Java doc README
Trial License Product License (PDF)
Download

Copyright © 1997-2008 OOP-Research CorporationTM, All Rights Reserved.

Valid XHTML 1.0! Valid CSS!