Search code examples
javaaspectjaopaspects

What is AspectJ good for?


First let me note, that I use AspectJ and I like it, but what else can I do with it.

I know AspectJ can be/is used for Logging. In some cases it is used for Transaction controlling – mostly implemented in conjunction with annotations. AspectJ can also be used to enhance classes with (code-generated) methods, like Spring Roo does.

But I believe AspectJ and AOP in general, can be used for more than: logging, transaction controlling, and simulation partial classes.

So what are other useful use cases for AspectJ and AOP?


Solution

    • permission check
    • interrupt action that takes too long
    • run action in separate thread or even in context of different process or event on other machine
    • monitoring
    • preparing any data / environment before call and processing results after call
    • opening / closing resources

    EDIT

    Although many years passed since I gave this answer I decided to add the following to make the answer more complete.

    • security check.
    • fixes of incorrect or behavior of API that you cannot change. For example boolean method that returns false in some conditions but should return true. You can fix this using AspectJ.