Synchronized pointcuts in aspect

I am creating a Rest server with aspectj. For synchronization I want to use aspects. I defined a pointcut to capture all the points where update and delete events occur: I defined an annotation and used the annotation to capture methods for synchronization:

synchronized pointcut syncJoinPoints():call (@Synchronizes * *(..)); 

What happens if a pointcut is synchronized, which means having a synchronized pointcut. Is the thread that intercepts the pointcut re-created by the AspectJ plugin, or uses the thread that introduces the intercept method?

Thank you for your help.

+4
source share
1 answer

AspectJ does not create threads by itself: weaving β€œonly” changes the code by introducing some additional instructions, but it continues to work in the same context.

The synchronized in a pointcut definition does nothing useful. If you want to synchronize all calls (or executions, which would mean less modified code), for methods annotated with @Synchronizes in the same lock, you need advice:

 public aspect SynchronizingAspect { private static final Object lock = new Object(); pointcut syncJointPoint(): execution(@Synchronizes * *.*(..)); // or call() Object around(): syncJointPoint() { synchronized(lock) { return proceed(); } } } 
+5
source

All Articles