It's not necessary to synchronize the calls to database if you take care in
writing the SQL code. For example if you use a SEQUENCE in ORACLE to get
next available ID, there is no possibility of a conflict. Also rather than
synchronizing, you can always get a lock(implicitly most of the time)
explicitly if there is a need. Almost all relational databases take care of
concurrency issues.
thanks
Vivek
-----Original Message-----
From: Nic Ferrier [mailto:[EMAIL PROTECTED]]
Sent: Friday, May 26, 2000 9:58 AM
To: [EMAIL PROTECTED]
Subject: Re: synchronized methods - simple question
>>> Steven Costello <[EMAIL PROTECTED]> 26-May-00 2:16:49 PM
>>>
>This discussion got me re-thinking my implementation in terms
>of synchronizing my methods which make database queries or
>updates.
>Is it necessary to synchronize all of the methods that access a
>database? Just the updates? or none at all? I have several
>different servlets accessing the database. Maybe I was being
>naive, but I was assuming that the database was taking care of
>the synchronization issues involved in accessing the database?
The calls is java.sql.Connection are not marked "synchronized" so
that is a hint that you may have to synchronize them.
It would depend rather on the database implementation.
However, you may have to synchronize anyway depending on your
application.
Consider the common (at least in 2 tier systems) trick of getting the
next available ID from a table and then updating the table:
ResultSet id=someconnection.executeQuery("some query returning
highest id");
String idval=id.getString("id");
someconnection.executeUpdate("some update using highest id just
obtained");
but of course this should be synchronized because otherwise an other
thread might cut in and cause a conflict with the same id.
This is quite common if you apply certain 2 tier designs to webapps.
Nic Ferrier
___________________________________________________________________________
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
___________________________________________________________________________
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