jeudi 23 novembre 2023

Reflection performance in Java or Spring

I'm transferring an old service written in Java to Spring. I noticed a significant drop in performance.I've identified that this code is responsible for it.The code below is called tens of thousands of times for objects.

Object helper = Class.forName(helperConfig.get(0)).newInstance();
((FieldHelperInterface) helper).setConnection(connection);
Method method = helper.getClass().getMethod(helperConfig.get(1), ResultSet.class);
value = method.invoke(helper, resultSet);

I know reflection is less efficient than direct calling, but why only after transferring to Spring? How to improve it? How to inject Spring "HelperInterface" components and call the methods indicated by their names?





Aucun commentaire:

Enregistrer un commentaire