The code below is used to create many beans and add them to a list for further usage
final List<Flow<Result>> tasks = new ArrayList<>();
for (long i : manyLongs) {
tasks.add((Flow<Result>) ctx.getBean("flowBeanName", "string" number));
}
manyLongs is an ArrayList of about 350000 items. Maybe more. I have noticed that this piece of code takes about 2 minutes to run. The Bean I am trying to create and add to tasks is a Prototype.
I can understand that creating 350K new objects may take time but 2 minutes seems a bit too much for a lightweight object of two fields. Is there a way to efficiently create those spring objects without altering the design altogether?
UPDATE
Luiggi Mendoza was right. I had two points in the constructor that took a toll on the object creation. The first was that I was a lazy loading call but the worst thing was the de-serialization of a JSON object in the constructor although it does not need to be there.
Just to test I checked creating the bean without Spring and although it is noticeably faster it is just a couple of seconds faster than spring.