Ugo Cei wrote:

Sylvain Wallez wrote:

Agree for *variables*. Here, we have a class member, which has to be loaded, then incremented, then stored.

So as Bertrand, I stay on the safe side and synchronize.


Just to be clear, what you're suggesting is to do:

public class MyClass {

  private int counter;

  public someMethod() {
    ...
    synchronized(this) {
      ++counter;
    }
    ...
  }
  ...
}


That's exactly this! More precisely:

public someMethod() {

   synchronized(this) {
       counter++;
   }
   try {
       blah();
   } finally {
       synchronized(this) {
           counter--;
       }
}

--
Sylvain Wallez                                  Anyware Technologies
http://www.apache.org/~sylvain           http://www.anyware-tech.com
{ XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }



Reply via email to