Question

Good day people. Right now in my web application I use a lot of Lists which will have to be sessionAttributes for my app. All this stored in one controller:

@Controller
@SessionAttributes({"institutionAttributes", "institutionTypeAttributes", "formDateAttributes", 
                        "formDescriptionAttributes", "deleteAttributesDescription", "deleteAttributesInstitution", "deleteAttributesDate"})
public class MainController {


    List<InstitutionInForm> listOfInstitutionsAttributes = new ArrayList<InstitutionInForm>();
    List<InstitutionTypeInForm> listOfInstitutionTypesAttributes = new ArrayList<InstitutionTypeInForm>();
    List<FormDate> listOfFormDateAttributes = new ArrayList<FormDate>();
    List<FormDescription> listOfFormDescriptionsAttributes = new ArrayList<FormDescription>();


    List<FormDescription> listOfFormDescriptionsDeleteAttributes = new ArrayList<FormDescription>();
    List<InstitutionInForm> listOfInstitutionDeleteAttributes = new ArrayList<InstitutionInForm>();
    List<FormDate> listOfDatesDeleteAttributes = new ArrayList<FormDate>();

//other methods omitted

Each of this Lists will initialize with initial value 10 and it takes some memory also. I decide to separate them by separating controllers.

So, I'm asking how it will initialize controllers all right on start up my application or when DispatcherServlet will get request from user, find a proper controller on after initialize them with all Lists inside.???

How can I prevent initializing don't needed at the moment controllers and Lists so on?

Thank you developers. Good productive coding day.

Was it helpful?

Solution

You can Use @Lazy to prevent eager loading/initialisation of your controller bean
This will get instantiated once first request comes.

@Lazy
@Controller
public class MainController { ...}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top