Question

I have to use JavaBeans in my application.

  • The application is a config driven application. Depending on config, different JavaBeans Classes will be required.
  • One option is that depending on configuration, I use a code generator to generate JavaBean classes.
  • Other option that sounds very appealing is use Dynamic Beans from Apache Beanutils. It saves me from one extra step of Code generation.

Can you please help me that what are the performance and memory implications of using Dynabeans vs Generated JavaBeans. Is there any better alternative to DynaBeans?

In both cases, I will be using Apache BeanUtils to invoke getters/setters later.

Was it helpful?

Solution

I have been looking at BeanUtils implementation of BasicDynaBean and have reached at following conclusion regarding comparison with Code Generated JavaBean.

Memory

  • BasicDynaBean uses a HashMap to store keys/values. If there are 1000 instances of sme DynaBean then lot of memory is being wasted because keys are being stored again in each instance. Therefore it is more memory consuming that a code generated JavaBean and would not recommend this if you are going to store a large no of instances of Dynabean in memory.

Speed

  • To access the different fields, it invokes get/put methods on HashMap. Therefore it is faster than Code Generated Java Beans because there I will have to access the getter/setter methods using reflection
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top