Reputation: 1419
What is the difference between Interceptors and Callbacks? Can I use @AroundConstruct and @PostConstruct interchangeably, will they always be involve (more or less) the same time?
Upvotes: 2
Views: 433
Reputation: 5585
As pointed out in the comments, the overhead of either is probably negligible, and not worth worrying about until you actually have a real problem to talk about.
As for the sequence of events (and other differences), the javadocs for AroundConstruct and PostConstruct answer that.
AroundConstruct
must be defined on an interceptor, and the real constructor is invoked after the last such interceptor calls the proceed
method on the InvocationContext
. So these will technically run before the constructor, but you get control back after it runs (thus the name "Around
"), so you can do post-processing as well.
PostConstruct
can be use defined on an interceptor or on any void method with no parameters on the object itself. It is invoked after the container has finished with dependency injection (thus the name "Post
").
Upvotes: 2