Spring pointcut pointer differences (within execution)

Please ... can someone explain to me what is the difference between using the following spring pointcut pointers?

Using the "inside pointcut pointer":

<aop:pointcut expression="within(my.app.dao.impl.*)" id="commonDaoOperation"/> 

Using a "pointcut point":

 <aop:pointcut expression="execution(public * my.app.dao.impl.*.*(..))" id="commonDaoOperation"/> 

I use the second one in my web projects (and I think it is most often used), the problem I found with this approach is that it consumes a lot of memory on the heap ...

After analyzing the heap dump of the application server with the eclipse memory analyzer, I found that my application consumes 450 MB, and instances of the class "org.springframework.aop.aspectj.AspectJExpressionPointcut consume 30% of these 450 MB ..

Each AspectJExpressionPointcut instance takes 6 MB (approximately), and this is due to the fact that each instance maintains a match cache for java.lang.reflect.Method instances and, surprisingly, there are many Java caching methods (methods that my pointcut expression does not mentions).

After reading the spring Documentation, I decided to use the first approach (in the pointcut pointer), and now each instance of AspectJExpressionPointcut takes up much less memory.

The question is ... what is the difference in performance between the two ...

Thank you very much in advance...

+9
java spring spring-aop
source share
2 answers

Spring documentation explains the difference:

  • execution - to map the connection points of the method, this is the main pointcut pointer that you will use when working with Spring AOP
  • inside - limits the correspondence of junction points in certain types (just executing a method declared in the corresponding type when using Spring AOP)

In other words, execution corresponds to the method and within corresponds to the type.

In this case, your pointcuts are pretty much equivalent. Your within matches any type in the my.app.dao.impl package, and your execution matches all public methods of any type in the my.app.dao.impl package.

However, execution implemented, I think, with an interceptor for each consistent method (many objects) that within needs only one interceptor, since it corresponds to the whole type (very small objects).

+4
source share

execute () matches join points that are method execution. This is the only pointer that actually matches. All other notations (supported by Spring AOP) limit only these matches. Note that Spring only supports the subset of pointers available in AspectJ (Spring AOP is proxy based). Designations of AspectJ points supported in Spring: args () and @args (), target () and @target (), Within () and @within (), execute (), this (), @annotation

0
source share

All Articles