synchronisation at a Java level here won't help you.
Imangine a scenario where you synchronize all the database access within
your VM, the database is a shared resource so anybody outside your VM can
access it independantly of you - this is why we have transactions.
If you're concerned about synchronized DB access then call
Connection.setAutoCommit(false) and then commit the DB calls yourself - the
database will then take care of locks and synchroisation,
Kevin Jones
DevelopMentor
www.develop.com
> -----Original Message-----
> From: A mailing list for discussion about Sun Microsystem's Java Servlet
> API Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of Nic
> Ferrier
> Sent: 26 May 2000 14:58
> 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