Arch2Arch Tab BEA.com
Syndicate this blog (XML)

BeanUtils: The Power and Cost

Bookmark Blog Post

del.icio.us del.icio.us
Digg Digg
DZone DZone
Furl Furl
Reddit Reddit

Prakash Malani's Blog | May 13, 2005   5:34 PM | Comments (3)


The Apache Jakarta Commons project is very useful. There are many popular commons components that I have used directly and indirectly on different projects. One such powerful component is BeanUtils. Let me illustrate a very powerful way of using BeanUtils to convert local entity beans into corresponding value objects:


BeanUtils.copyProperties(aValue, aLocal)

The above code copies the properties from aLocal object into aValue object. That is simple! The above code works regardless of the number of properties in the local (and corresponding value) object. Let us assume that the local object has 100 properties. The above one line saved us from typing at least 100 lines of tedious, error-prone, and repetitive get and set method calls. Wonderful! Powerful! Useful!

Now, the bad news: the cost of using BeanUtils is prohibitively expensive! On simple tests that I did, the cost of BeanUtils was more than the total time to fetch the data, copy them to the corresponding value objects (manually by calling get and set methods), and returning them via serialization to a remote client. Yikes! So wield the power with care.

Please drop me a note and share your experiences with BeanUtils and similar utilities.
+prakash


Comments

Comments are listed in date ascending order (oldest first) | Post Comment

  • BeanUtils caches all PropertyDescriptor objects obtained from java.beans.Introspector in a static map. As a result, the initial call to BeanUtils for a specific class will pay the price of reflection. Subsequent calls, however, are much less expensive. Your performance experiments ought to be performed in a loop, then compute the average elapsed time without taking the initial call into account. I think you'll see much improved performance.

    Struts uses copyProperties() to copy request parameters to a corresponding FormBean. The resulting performance is quite good.

    Posted by: tom.drake@tavant.com on May 18, 2005 at 2:19 PM

  • This is great! I did perform the testing in a loop. The results are from the average run in a loop. Any other suggestions and comments are most welcome, +prakash

    Posted by: pmalani on May 18, 2005 at 3:58 PM

  • perharps BeanUtils can

    Posted by: RyanGuo on May 29, 2005 at 7:22 PM



Only logged in users may post comments. Login Here.

Powered by
Movable Type 3.31