Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

thread safe JDBC code

 
   Database Help (Home) -> Java RSS
Next:  Accessing mainframe DB2 in Java.  
Author Message
Steve

External


Since: Jan 15, 2008
Posts: 3



(Msg. 1) Posted: Sun Mar 23, 2008 4:40 pm
Post subject: thread safe JDBC code
Archived from groups: comp>lang>java>databases (more info?)

How to guarantee the JDBC code is thread safe? Should we put
synchronize block in JDBC methods that performs update/delete
operations?

please advice. thanks.

 >> Stay informed about: thread safe JDBC code 
Back to top
Login to vote
Arne_Vajhøj

External


Since: Mar 02, 2008
Posts: 37



(Msg. 2) Posted: Sun Mar 23, 2008 8:46 pm
Post subject: Re: thread safe JDBC code [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Steve wrote:
> How to guarantee the JDBC code is thread safe? Should we put
> synchronize block in JDBC methods that performs update/delete
> operations?

The exact same thread safe rules applies to code using JDBC as
any other code.

If you are worried about the database, then don't think
synchronized - think transactions and transaction isolation
level.

Arne

 >> Stay informed about: thread safe JDBC code 
Back to top
Login to vote
Arved Sandstrom

External


Since: Mar 25, 2008
Posts: 16



(Msg. 3) Posted: Tue Mar 25, 2008 5:56 pm
Post subject: Re: thread safe JDBC code [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"Steve" wrote in message

> How to guarantee the JDBC code is thread safe? Should we put
> synchronize block in JDBC methods that performs update/delete
> operations?
>
> please advice. thanks.

Here are some articles (despite the titles, not MySQL specific) that discuss
the general problem:

http://www.mysql.com/news-and-events/newsletter/2003-04/a0000000154.html

Key phrases: "The answer to this problem is to realize that a unit of work
is scoped by a java.sql.Connection instance. In fact, even transaction
control is scoped to a java.sql.Connection, via Connection.setAutoCommit(),
Connection.commit() and Connection.rollback(). Therefore, let only one
thread at a time use a Connection instance to do its unit of work. There are
multiple strategies for doing this, from giving each thread its own
Connection instance, or sharing Connection instances via a Connection pool."

Note: one can also use ThreadLocal.

http://dev.mysql.com/tech-resources/articles/connection_pooling_with_c...ectorj.

Has code example. Recall that local variables are unique to a thread, unlike
instance and class variables. Therefore, if thread A gets a connection
locally then Threads B and C won't be accessing it.

AHS
 >> Stay informed about: thread safe JDBC code 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
jdbc - Hi. Is it possible to use java/jdbc to lengthen columns in, say, ms sql tables? Please note (sorry) I already asked this in an ms sql group... it is not quite a cross post, but an after thought that I might get some good information here. Thanks Jeff

JDBC - Hi,i am total newbie in java programming.I want help in connecting Oracle 9i database and inserting data in a table there.How can i do this?Can anyone explain me step-by-step or point me to any link where i can learn this?I am using tomcat 6.0.16 and..

Newbie help needed JDBC - Hi, I have grown up with VB6 and moved onto perl / php. I have got JBOSS running under suse 9.2, and have netbeans as well. I can understand the mechanism for java applets and played with a few. The next step i need help with is 1) what is a class 2)...

JDBC test suite - Do you know of any good JDBC test suite? I developes an java DB and I want to check it compliant with the JDBC standard and SQL 92. Thanks

Sybase, JDBC, AutoCommit, DDL IN TRAN - Hi All, I am hoping someone can help me with the following problem I'm having executing Sysbase stored procedures via JDBC. When I execute a stored procedure which contains DDL and with AutoCommit set to false I get the following exception. ..
   Database Help (Home) -> Java All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]