Jean-Louis.Pasturel schrieb: > so, for example, if i increment counters, compute values ( average, > max, min, standard deviation...) or write logs in a file, all these > part of codes *must* be synchronized as in a regular method. All these > values are shared between threads.
basically yes, but it *really* depends on the big picture. There is nothing AspectJ specific with this topic. It is as with every line of code intended to run in a multithreaded/server enviroment. Synchronisation *could* be an issue. But it's no good idea to synchronise every method by default. To give a very common example: Logging. Supposed, you write an aspect, which uses a worm hole to remember the return value of some calculation, and then with another advice, you pick up this value to log it, together with the complete invocation context. Now, what is the greater danger? - maybe messing up the log by adding the return value generated by another thread? - killing the overall performance of the service in question by lock contention? You just can't tell the right answer without knowing the exact situation. Regarding Aspects, there is only one general advice I can give, based on my experience: You should be reluctant to do implementation-level stuff from Advice. It is always better to invoke an API or an existing service. (And following this reasoning, locking and managing the state would be the service's job, not the job of the aspect). Cheers, Hermann V. _______________________________________________ aspectj-users mailing list [email protected] https://dev.eclipse.org/mailman/listinfo/aspectj-users
