-
Connection Pooling...
Hi All,
Some of my confusion is about how to do connection pooling with JSP and Tomcat.
I have used connection pools with ATG Dynamo but I'm not sure how to proceed
without a big application server to handle it? Can you shed some lights?
Thanks
Ellen
-
Re: Connection Pooling...
You can use Datasources in JSP it self using JNDI
"Ellen Miles" <csc015@yahoo.com> wrote:
>
>Hi All,
>Some of my confusion is about how to do connection pooling with JSP and
Tomcat.
>I have used connection pools with ATG Dynamo but I'm not sure how to proceed
>without a big application server to handle it? Can you shed some lights?
>
>Thanks
>Ellen
-
Re: Connection Pooling...
>>Hi All,
>>Some of my confusion is about how to do connection pooling with JSP and
>Tomcat.
>>I have used connection pools with ATG Dynamo but I'm not sure how to proceed
>>without a big application server to handle it? Can you shed some lights?
>>
Since you do not have an application server , you
will have to build your own connection pool that maintains a
number of javax.sql.Connection objects.
One way of doing this will be to have a singleton connection
pool object which will have a getConnection and returnConnection method.
Clients will do this :
java.sql.Connection con = ConnectionPool.getInstance().getConnection() ;
//Do something with the connection
//
//Now return it back
ConnectionPool.getInstance().returnConnection( con ) ;
The ConnectionPool object will read from a config file
maxConnection and minConnection property to figure out how many
connections to start with in the pool and whats the maximum
size of the pool.
And once you reach the max size you refuse to dole out a connection.
The pool itself may be built using a hashtable.
The key for the hashtable is the hash of the Connection object
that you create. And the key will point to an object that stores
the actual connection object and a boolean flag indicating whether the connection
is being used by someone or not.
On invocation of getConnection you scan through the hash table
until you find a connection that is free. Set the flag to busy
and return the connection.
Once someone calls a returnConnection , get the hash of the Connection object,
find the entry in the hashtable , set the
flag to free and return.
Of course there are whole lot of error condition checks/performance related
algos here and multithreaded issues.
Later you can add a thread in the background that checks for
stale connection in your pool periodically and/OR timout for
a connection(For example you give up on a hash table entry because a rogue
client has not returned your connection
within a prespecified amount of time).
You can also decide to recycle your connection pool after a
certain amount of time automatically.
Hope this helps.
Kingshuk
-
Re: Connection Pooling...
I use free connection pool from javaexchange.com
"Ellen Miles" <csc015@yahoo.com> wrote:
>
>Hi All,
>Some of my confusion is about how to do connection pooling with JSP and
Tomcat.
>I have used connection pools with ATG Dynamo but I'm not sure how to proceed
>without a big application server to handle it? Can you shed some lights?
>
>Thanks
>Ellen
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks