Please... can anybody explain me what are the differences between using the following spring pointcut designators?
Using "within pointcut designator":
<aop:pointcut expression="within(my.app.dao.impl.*)" id="commonDaoOperation"/>
Using "execution pointcut designator":
<aop:pointcut expression="execution(public * my.app.dao.impl.*.*(..))" id="commonDaoOperation"/>
I am using the second one in my web-projects (and I think it's the most used), the problem i have found with this approach is that it's consuming a lot of memory in the heap...
After analyzing the "heap dump" of the application server with the "eclipse memory analyzer" i have found that my application is consuming 450 MB and the instances of the class "org.springframework.aop.aspectj.AspectJExpressionPointcut
" are consuming 30% of those 450MB...
Each instance of AspectJExpressionPointcut
occupy 6 MB (approximately) and this is because each instance mantains a cache of matches with instances of java.lang.reflect.Method and surprisingly there are a lot of java methods cached (methods that my pointcut expression doesnt mentions).
After Reading Spring Documentation, I decided to use the first one approach (within pointcut designator) and now each instance of AspectJExpressionPointcut
occupy much less memory.
The question is about that... what is the difference in performance between them...
Many thanks in advance...
The Spring documentation explains the difference:
In other words,
execution
matches a method andwithin
matches a type.In this case, your pointcuts are pretty much equivalent. Your
within
matches any type in the packagemy.app.dao.impl
and yourexecution
matches all the public methods of any type in the packagemy.app.dao.impl
.However,
execution
is implemented, I think, with an interceptor for each matched method (a lot of objects), whichwithin
only needs one interceptor since it matches the entire type (very little objects).