Hands-On High Performance with Spring 5
by Chintan Mehta, Subhash Shah, Pritesh Shah, Prashant Goswami, Dinesh Radadiya
Aspect instantiation models
By default, the declared aspect is singleton, so there will be only one instance of our aspect per class loader (and not per JVM). The instance of our aspect will be destroyed only when the class loader is garbage.
If we need to have our aspect with private attributes hold data relative to class instances, the aspect needs to be stateful. To do so, Spring with its AspectJ support provides a way using perthis and pertarget instantiation models. AspectJ is an independent library, and has other instantiation models in addition to perthis and pertarget, such as percflow, percflowbelow, and pertypewithin, which are not supported in Spring's AspectJ support.
To create a stateful aspect using perthis, we need to declare ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access