AspectJ compiler (ajc) vs load-time weaving

倖福魔咒の 提交于 2019-12-04 09:28:50

问题


Several questions here:

  • Does ajc change all the classes it compiles (even non-aspect ones)? What if I comiple only aspect classes ant then put them in the same classpath with the common ones?

  • Does the ajc-compiled project perform faster then the one that uses load-time weaving?

  • What if I need to write a library, that does tracing with AspectJ, and then I want this library to work with ANY project? Is load-time weaving the only option in this case?


回答1:


  1. ajc (compile time) will only change classes that are affected by aspects. Remember, ajc is an extension of a Java compiler (to be precise, it is based on Eclipse 3.3's JDT compiler). So, it will compile all your Java classes as would a normal Java compiler. It will then additionally weave all classes that are affected by an aspect. If you compile your aspects separately from your non-aspects then there will be no compile time weaving going on and your aspects will not have any affect. However, you can put your aspects on the aspect path of the compilation of your non-aspects (if your non-aspects are compiled by ajc). This will allow your non-aspects to be woven by your aspects.
  2. Start-up time under CTW is much better than LTW, but after all classes are loaded, speed difference should be negligible. The reason is that under LTW, all classes are woven when they are loaded. This means that classloading requires the additional step of weaving which is not necessary under CTW.
  3. No. As mentioned above, you can add the aspects to your aspect path of the second project, and then they will be woven during compilation.

More on Aspect path:

http://www.eclipse.org/aspectj/doc/released/devguide/ajc-ref.html



来源:https://stackoverflow.com/questions/5717883/aspectj-compiler-ajc-vs-load-time-weaving

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!