Many modern frameworks (Spring, Hibernate) provide very nice dynamic behaviors with use of Java dynamic proxies, but what's the exact performance cost associated with it? Are there public benchmarks available for Sun JVM?
A dynamic proxy class is a class that implements a list of interfaces specified at runtime such that a method invocation through one of the interfaces on an instance of the class will be encoded and dispatched to another object through a uniform interface.
JDK Dynamic Proxies allow one to create implementations of Java interfaces at runtime by the means of Reflection. A proxy may be seen as a subject that will forward method calls to target instances and eventually return any result produced by the target instance to the caller.
Proxy is a structural design pattern that provides an object that acts as a substitute for a real service object used by a client. A proxy receives client requests, does some work (access control, caching, etc.) and then passes the request to a service object.
Spring used two types of proxy strategy one is JDK dynamic proxy and other one is CGLIB proxy. JDK dynamic proxy is available with the JDK. It can be only proxy by interface so target class needs to implement interface.
A few pointers:
I don't know if there is any performance analysis in the framework you mentioned, but in my project lambdaj I made a very large use of dynamic proxy using the same technology (cglib). In the pdf that explains how my library works you can also find an interesting performance comparison on this subject.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With