Multiple Threads Accessing The Same Connection

Multiple Threads Accessing The Same Connection

Post by Ben » Fri, 16 Mar 2001 04:45:10



If multiple threads, say from several instances of a servlet, are executing
statements on a shared connection will the results be corrupted?  Is there a
performance benefit to having multiple connections through a connection pool
if there is no corruption?  Would use of a shared connection to create sql
statements need to be synchronized?

Thank you for your help,

Ben Fornshell

 
 
 

Multiple Threads Accessing The Same Connection

Post by thomasdevo » Fri, 16 Mar 2001 05:12:54


I'm not really sure you are going to have problems but to me it seems not a
good way of accessing your DB.
For each resultSet (query, or whatever) use another connection until you are
finished with the resultset and then put it back in the pool and reuse when
necessary. This is the way I work and then you will not have any other
problems.
So in your servlet create a pool, make sure there is only one pool active,
initialize in the servlet init method and use your pool to get a connection
every time you have a new request, when your rquest is finished the put it
back in the pool.

Thomas De Vos

> If multiple threads, say from several instances of a servlet, are
executing
> statements on a shared connection will the results be corrupted?  Is there
a
> performance benefit to having multiple connections through a connection
pool
> if there is no corruption?  Would use of a shared connection to create sql
> statements need to be synchronized?

> Thank you for your help,

> Ben Fornshell



 
 
 

Multiple Threads Accessing The Same Connection

Post by Per Schr?d » Fri, 16 Mar 2001 20:56:14




>If multiple threads, say from several instances of a servlet, are
>executing statements on a shared connection will the results be
>corrupted?  Is there a performance benefit to having multiple
>connections through a connection pool if there is no corruption?  Would
>use of a shared connection to create sql statements need to be
>synchronized?

>Thank you for your help,

>Ben Fornshell


According to the Sun documentation for driver writers, JDBC drivers should
be fully thread-safe. See chapter A.1.6 in:

http://java.sun.com/products/jdbc/driverdevs.html

However, many drivers will implement internal synchronization so that only
one query is running at a time on a given connection object. In order to
get true concurrency you may have to use several connections.

/Per Schr?der
http://www.mimer.com

 
 
 

Multiple Threads Accessing The Same Connection

Post by Per Schr?d » Sat, 17 Mar 2001 20:35:00






>> According to the Sun documentation for driver writers, JDBC drivers
>> should be fully thread-safe. See chapter A.1.6 in:

>> http://java.sun.com/products/jdbc/driverdevs.html

>> However, many drivers will implement internal synchronization so that
>> only one query is running at a time on a given connection object. In
>> order to get true concurrency you may have to use several connections.

>> /Per Schr?der
>> http://www.mimer.com

>I have never used a JDBC connection that could be used this way.  Open a
>connection, use it, then pass it on (or close it)

I'm not sure what you mean. Have you never used a JDBC driver that complied
with the SUN specification I referenced?

Note that the SUN documentation merely says that multi-threaded
applications can use the same objects without corruption. It does not say
that the driver has to provide true concurrency for those threads.

Regards,
Per Schr?der
http://www.mimer.com

 
 
 

Multiple Threads Accessing The Same Connection

Post by Jared Richardso » Sat, 17 Mar 2001 09:46:53





> >If multiple threads, say from several instances of a servlet, are
> >executing statements on a shared connection will the results be
> >corrupted?  Is there a performance benefit to having multiple
> >connections through a connection pool if there is no corruption?  Would
> >use of a shared connection to create sql statements need to be
> >synchronized?

> >Thank you for your help,

> >Ben Fornshell

> According to the Sun documentation for driver writers, JDBC drivers should
> be fully thread-safe. See chapter A.1.6 in:

> http://java.sun.com/products/jdbc/driverdevs.html

> However, many drivers will implement internal synchronization so that only
> one query is running at a time on a given connection object. In order to
> get true concurrency you may have to use several connections.

> /Per Schr?der
> http://www.mimer.com

I have never used a JDBC connection that could be used this way.  Open a
connection, use it, then pass it on (or close it)
 
 
 

1. Multiple threads Cause Connection Busy Error in the Driver

*** post for FREE via your newsreader at post.newsfeeds.com ***

 my question is with reference to above bug as described in
 http://support.microsoft.com/support/kb/articles/Q175/9/04.ASP

 I have multiple active stmts, how can i get rid of this problem? or how to
 cancel/reset other stmts? any tip/help? :)

 thnkx

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 90,000 Newsgroups - 16 Different Servers! =-----

2. Sample ABF Employee application from manuals needed!

3. Random Numbers in PL/SQL

4. BUG: Multiple threads Cause Connection Busy Error in the Driver

5. OracleDBA-Minneapolis

6. pgsql/src/bin/scripts (createdb createlang.sh createuser dropdb droplang dropuser vacuumdb)

7. Error HY000 Connection busy - when multiple threads write to One SQL Server table

8. BUG: Multiple threads Cause Connection Busy Error in the Driver

9. TechTips: Handling database connections for multiple threads

10. Multiple connections in a single thread

11. Multiple Threads using /one/ Connection?