DynaBeans vs CodeGenerated JavaBeans performance implications
-
30-06-2021 - |
Pregunta
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.
Solución
I have been looking at BeanUtils
implementation of BasicDynaBean
and have reached at following conclusion regarding comparison with Code Generated JavaBean.
Memory
BasicDynaBean
uses aHashMap
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 onHashMap
. Therefore it is faster than Code Generated Java Beans because there I will have to access thegetter/setter
methods usingreflection
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow