tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Malia Noori" <mno...@blueridgenetworks.com>
Subject RE: method level synchronization doesn't work
Date Thu, 30 Sep 2004 14:43:22 GMT
Actually, the data that I am modifying requires a transaction and
synchronization.  It increments a counter stored in the database.  So, I
have to do a select to get the current value, increment the counter, and
then insert the new value.  So if two threads are accessing it at the same
time, the counter will not be properly incremented.  What's puzzling is that
method level synchronization does not work while synchronizing on a block of
code inside a method works. 

Thanks,
Malia

-----Original Message-----
From: Peter Lin [mailto:woolfel@gmail.com] 
Sent: Thursday, September 30, 2004 10:26 AM
To: Tomcat Users List; mnoori@blueridgenetworks.com
Subject: Re: method level synchronization doesn't work

am I missing something, but looks like you're trying to build some
kind of web cache. why not use Hibernate or something that already
does caching for you instead?

the only time I can see a need to sync, is if the request contains
data that requires a transaction. Which in that case, you're better
off doing an insert, then a second select query with the same
connection.

or is the scenario a distributed objects setup?

peter


On Thu, 30 Sep 2004 10:05:41 -0400, Malia Noori
<mnoori@blueridgenetworks.com> wrote:
> Hi,
> 
> I am using Tomcat 4.1 and I am accessing MS SQL Server database via JDBC.
I
> have a JSP that calls a web bean.  This web bean has a section of code
that
> I want to synchronize, but when I synchronize the method, Tomcat doesn't
> actually synchronize the threads.  (I tried this by having 2 users access
my
> JSP at the same time).  When I synchronize the code in the method by using
a
> mutex, it works.
> 
> So, doing this doesn't work:
> 
> public synchronized void amethod()
> 
> {
> 
>  //some code that access the database and needs to be synchronized
> 
> }
> 
> But doing this works:
> 
> public void amethod()
> 
> {
> 
> String mutex = "";
> 
> synchronize(mutex)
> 
> {
> 
>  //some code that access the database and needs to be synchronized
> 
> }
> 
> }
> 
> Why does synchronization on the method doesn't work?  Does Tomcat not
allow
> locking of object caused by method level synchronization?  Any help will
be
> appreciated.
> 
> Thanks,
> 
> Malia
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message