tag:blogger.com,1999:blog-9179083971977974353.post5503940498833381569..comments2022-03-28T05:36:44.465+02:00Comments on Insufficient Information: Spring AOP: Dynamic Proxies vs. CGLib proxiesjoerg20http://www.blogger.com/profile/07387500155278923580noreply@blogger.comBlogger11125tag:blogger.com,1999:blog-9179083971977974353.post-66573331884880640212011-04-08T14:47:51.529+02:002011-04-08T14:47:51.529+02:00thanks Joerg.you helped me to solve the problem re...thanks Joerg.you helped me to solve the problem regarding proxyvishal thakurhttps://www.blogger.com/profile/01150225371806421653noreply@blogger.comtag:blogger.com,1999:blog-9179083971977974353.post-65966713030940845762010-12-21T10:16:16.788+01:002010-12-21T10:16:16.788+01:00Hello Joerg.
I have solved my problem without pr...Hello Joerg. <br /><br />I have solved my problem without proxying twice. Avoiding that I'll explain which was the problem and which solution I applied. Anyway, I'd know if cglib and jdk proxies could work together -without taking care of awkwardness :)-<br /><br />Introduce yourself telling you that I'm developing a framework for my application that stands on another one that I can't modify.<br /><br />Their framework force us to work with spring-jdbc, and we have developed our own ORM with jdk proxies that emulates hibernate.<br /><br />Those proxies work for Business Objects.<br /><br />Ok. In another way, we have developed an StateMachineFilter that gets a request parameter called "flowPID", and if this parameter is present we do flowable actions (start actions - chain.doFilter - end actions). <br /><br />But we found the problem that struts redirections work within the same http request, so, the filter wraps both actions and end action were executed later than expected.<br /><br />I thought that proxing actions could be a solution ¿couldn't it?, but I decided to manage it by setting the active flowPID in the application context and creating an Aspect (AOP) over Facade calls, cause we assume that there's only one business call on each action.<br /><br />Many thanks Joerg.Miguelhttps://www.blogger.com/profile/03407507878929771421noreply@blogger.comtag:blogger.com,1999:blog-9179083971977974353.post-56284480085193289542010-12-20T18:37:10.942+01:002010-12-20T18:37:10.942+01:00Hi Miguel,
Sorry for replying that late. I was ve...Hi Miguel,<br /><br />Sorry for replying that late. I was very busy lately. On your issue:<br /><br />I don't know your exact requirement but proxying Action classes sounds a bit awkward. What functionality has to be implemented on that level? Have you thought about introducing an additional layer below your Action classes and moving the functionality over there? This approach might be more reusable.<br /><br />Extracting an interface from Struts' Action class and letting your Actions implement this should be a very simple solution. The techniques you use should rather adopt to the application than the other way around. Also, using CGLib and Dynamic Proxies in parallel should be no problem. Just make sure you don't proxy an instance multiple times. Just by using both approaches in parallel there should be no performance issue.joerg20https://www.blogger.com/profile/07387500155278923580noreply@blogger.comtag:blogger.com,1999:blog-9179083971977974353.post-77988440558420790232010-11-25T11:54:39.314+01:002010-11-25T11:54:39.314+01:00Hello Joerg.
I'm working with a spring-struts...Hello Joerg. <br />I'm working with a spring-struts application where jdk proxies are working fine, but I have a new requeriment that leads me to proxy Struts Actions classes.<br />By now, they aren't interfaced, and of course, jdk proxy doesn't work with.<br />So, I have three options. <br />- Modify everything to work with cglib2.<br />- Generate interfaces for Actions.<br />- Work with both proxies. ¿Is it possible to work with on spring?<br />It would be great if we could combine them, but I think that if possible it must attempt to application performance. Isn't it?Miguelhttps://www.blogger.com/profile/03407507878929771421noreply@blogger.comtag:blogger.com,1999:blog-9179083971977974353.post-31108820130294689402009-05-08T08:51:00.000+02:002009-05-08T08:51:00.000+02:00Diego, that's not what I meant. As a side note, I ...Diego, that's not what I meant. As a side note, I also prefer constructor injection over setter injection.<br /><br />With the class' state I mean static variables like instance counters. Only for those it would be problematic if the constructor is called twice, once for the proxy and once for the wrapped object.joerg20https://www.blogger.com/profile/07387500155278923580noreply@blogger.comtag:blogger.com,1999:blog-9179083971977974353.post-9221747100854146172009-05-08T02:20:00.000+02:002009-05-08T02:20:00.000+02:00"I consider changing the class' state based on con..."I consider changing the class' state based on constructor calls a code smell anyway."<br /><br />Constructors are particularly useful to do dependency injection, so, no code smell to me :)Diego Plentzhttps://www.blogger.com/profile/12338682961321699284noreply@blogger.comtag:blogger.com,1999:blog-9179083971977974353.post-20526194170197326712008-01-12T06:46:00.000+01:002008-01-12T06:46:00.000+01:00Thanks Oleksandr. Since there are no serious perfo...Thanks Oleksandr. Since there are no serious performance issues with the one or the other method I don't consider performance as a decisive criterion. That's why I never really cared about performance. First I want to have a good design, then I start to make compromises if it is necessary ;-)<BR/><BR/>Also originally this post was really intended as comparison between dynamic proxies and CGLib proxies and not so much about Spring's AOP in general. Since I added the other common issues I should probably have added this point as well. I'm going to update the post. Though I have to admit it is really too obvious to me :-)joerg20https://www.blogger.com/profile/07387500155278923580noreply@blogger.comtag:blogger.com,1999:blog-9179083971977974353.post-86989390977850929802008-01-07T09:50:00.000+01:002008-01-07T09:50:00.000+01:00Concerning performance comparision - it highly dep...Concerning performance comparision - it highly depends on JDK version. Prior to JDK 1.4.2 dynamic proxies were noticeable slower, starting from 1.4.2 - marginally faster then CGLIB-based proxies. Hibernate JIRA contains some interesting discussion on this matter.<BR/><BR/>But there is much more important issue omitted from discussion. IT was not mentioned, that whole proxy-based AOP (CGLIB or not) does not cover objects intantiated not by Spring but directly in code with new(). While it seems to be absolutely obvious, it is major cause of confusions and questions in forums just next to "in-object" calls.al0https://www.blogger.com/profile/15743792964167204705noreply@blogger.comtag:blogger.com,1999:blog-9179083971977974353.post-1576984986638941902007-12-23T04:48:00.000+01:002007-12-23T04:48:00.000+01:00Thanks Marten. Of course we can. This would increa...Thanks Marten. Of course we can. This would increase our spare time a lot :-)<BR/><BR/>Raptor, thanks for your comment. Personally I do not really care about the performance difference. I never tested it myself but only got from something I read somewhere ;-) Now that I stumbled upon a paragraph in the reference I updated the post.joerg20https://www.blogger.com/profile/07387500155278923580noreply@blogger.comtag:blogger.com,1999:blog-9179083971977974353.post-88647844649001205582007-12-20T13:16:00.000+01:002007-12-20T13:16:00.000+01:00Joerg, great post summing up the differences. Can ...Joerg, great post summing up the differences. Can we link this page as default with proxy questions ;-).Marten Deinumhttps://www.blogger.com/profile/14906946629329726590noreply@blogger.comtag:blogger.com,1999:blog-9179083971977974353.post-45503468639453821982007-12-19T10:47:00.000+01:002007-12-19T10:47:00.000+01:00I beg to differ on your point that CGLib proxies a...I beg to differ on your point that CGLib proxies are faster than Java dynamic proxies. In my personal experience, CGLib proxies perform slower.<BR/>This has been confirmed by several people on the net as well.Raptor T Wikedhttps://www.blogger.com/profile/14927329218035196900noreply@blogger.com