tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Steffen Heil" <li...@steffen-heil.de>
Subject AW: method level synchronization doesn't work
Date Thu, 30 Sep 2004 21:42:10 GMT
Hi

> I have to synchronize on the method ...

No you do not need to synchonize on the method, you need to synchronize.
You can synchronize on anything.

The easiest would be to do the following:

public static synchronized void amethod()
{
  //some code that access the database and needs to be synchronized
}

Just make your method static.

Synchonization will not occur on the instance object any more, but on the
Class object of your instance.
Since tomcat may instantiate multiple servlets, it may only do so in the
same classloader. Therefor all instances belong to the same Class object and
will synchronize as you required.

Regards,
  Steffen

Mime
View raw message