Shula
Shula

Reputation: 306

AspectJ - @Before, method and thread

In AspectJ:

@Before("execution(method_a)")
public void method_b() {
}
@Before("execution(method_a)")
public void method_c() {
}
  1. Does method_a and method_b have necessarily the same threadId?
  2. If method_b and method_c will be run parallel, method_a is thread safe?

Thanks alot

Upvotes: 0

Views: 1286

Answers (1)

kriegaex
kriegaex

Reputation: 67417

Disclaimer: I am really talking about AspectJ here because you asked that way, not about Spring AOP.

The answer is: AspectJ instruments Java byte code, but does not run in its own thread. Both advice method_b and method_c will run in the same thread as method_a (awful choice of names, BTW) unless you start your own threads from within advice.

As for the order in which the two advice pointing to the same joinpoint are executed, you can select it if both advice are in different aspects via @DeclarePrecedence. If they are within the same aspect, the order is as described here.

Upvotes: 3

Related Questions