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

 

Reply via email to