Dmitry Maximovich wrote:
>
> I'm just wondering, why do you need a connection "pool"?
> Probably it's enough to create one connection in method init() of servlet
> and then you could just create statements from one connection
> Statement stmt = conn.createStatement();
> and use it. As far as I know there is no interference between few threads
> or something like that,
> you could create as many Statements from one Connection object as you want
> and use it together in
> same time. Or I'm not right?
What you describe is an alternative to pools that have some disadvantages.
Your servlet is called by multiple threads at the same time to handle
concurrent requests. If you let each thread create and execute statements in
parallel you run the risk of creating inconsistent database state, since
transactions work on the connection level. So if one thread calls commit
or rollback, it affects all transactions on the shared connection. Another
problem is that some JDBC drivers are not able to handle concurrent
statements.
So you would have to serialize (synchronize) the use of the connection, so
that only one request at the time is handled. This has a very negative
performance impact.
With a pool, each thread gets its own connection and can use it without
interference from other threads and without need for serialization.
There are plenty of good connection pools available on the net for free
so I really recommend you to use one. I wrote an article about connection
pools, with source code included, for Web Developer's Journal a while back.
Check it out at
http://WebDevelopersJournal.com/columns/connection_pool.html
--
Hans Bergsten [EMAIL PROTECTED]
Gefion Software http://www.gefionsoftware.com
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html