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;
    }
    ...
  }
  ...
}

?

I don't think it is necessary, and could hurt performance, but before I try to dig up some other reference, I'd like to know if we're talking about the same scenario.

Ugo


The more correct version would be:

public class MyClass {
    private volatile int counter; //atomic

    public someMethod() {
        ++counter;
    }
}


Only longs on up should be actually synchronized.

I agree that either approach *will* without a doubt cause a bottleneck and hurt the scalability of Cocoon.



Reply via email to