Firstly, let me give some back-ground about Spring Transaction Management. Spring uses Proxies for transaction management and these proxies are JDK dynamic proxies. However, Spring uses CGLIB proxies when a bean class doesn’t implement an interface. A point to note, proxy as such delegates control to a transaction manager to manage transactions.
To understand how proxies are used in Spring, refer to Micheal Isvy’s blog.
A month ago, i was discussing with a colleague about the performance problems with proxying which is used left, right and center in Spring’s transaction management and other features. As i am a strong supporter of Spring, i couldn’t agree but at the same time couldn’t disagree with him. However, i am ready to take a stand now:
a. Proxies do add a performance over-head. A direct call to a method in target object always takes less time than a call through a proxy object. However, it is negligible compared to the benefits we reap out of a ready-to-use features without having to worry about writing code to do it.
b. The advice above, needs to be taken with a pinch of salt, though. Too much proxying results in performance problems. A better solution in such a situation would be to perform byte code weaving using AspectJ. This is achieved by using JavaAgent.
Courtesy: Alef Arendenson