Thank for your answer, but if don't mark Increments and Decrements with synchronize, is there a problem of accessing to the same variable at the same time from two different method ?
2009/9/21 Simon Nash <[email protected]> > Antonio Mirarchi wrote: > >> Hi, i have a question about invocation method between components; i have >> three component A,B,C. The component A have two remotable and OneWay methods >> Increments and Decrements, Increments call a private method inc to >> increments private variable in A implementation, and Decrements call a >> private method dec to decrements the same variable, if B and C call one of >> this method at same time is it correct to define the private method inc and >> dec as synchronized to obtain a synchronized access to the private variable >> ? Thank for your answer >> >> Hi Antonio, > There shouldn't be any problem with making the private methods > synchronized. Because AServiceImpl is composite scoped, the Tuscany > runtime will not synchronize calls to Increments() and Decrements(). > > Simon > > > Service A >> >> @Remotable >> public interface Aservice{ >> >> @OneWay >> void Increments(); >> @OneWay >> void Decrements(); >> } >> /--------------------------------------------------------------/ >> @Scope("COMPOSITE") >> @EagerInit >> public class AserviceImpl implements Aservice{ >> >> private int i; >> >> @Init >> public void start() { i=0;} >> >> private void inc(){i++;} //<------this may be synchronized? >> >> private void dec(){i--;} //<------this may be synchronized? >> >> >> public void Increments(){inc();} >> public void Decrements(){dec();} >> } >> >> >> Service B >> >> @Remotable >> public interface Bservice{ >> void Bmethod(); >> } >> /--------------------------------------------------------------/ >> @Scope("COMPOSITE") >> >> public class BserviceImpl implements Bservice{ >> @Reference >> Aservice aservice; >> >> public void Bmethod(){ >> . >> . >> aservice.Increments(); >> . >> . >> } >> >> } >> >> Service C >> >> @Remotable >> public interface Cservice{ >> void Cmethod(); >> } >> /--------------------------------------------------------------/ >> @Scope("COMPOSITE") >> >> public class CserviceImpl implements Cservice{ >> @Reference >> Aservice aservice; >> >> public void Cmethod(){ >> . >> . >> aservice.Decrements(); >> . >> . >> } >> >> } >> >> >
