Why DispatcherServlet Loading at first api call?

Why dispatcherServlet loading is not happening on application startup , instead it is getting loaded on first api call ?

Hi,

Lazy initialisation (on first request) is the default behaviour of Spring Boot for this Servlet.
If you want to change this behaviour you can control this with the property;

spring.mvc.servlet.load-on-startup=1

Why would you want to change this default behaviour?

This is all Spring related. Please check the Spring documentation for more info.

Regards,

Yvo

Reading your question again I need some more info.
There are several servlets that get initialized. For example; REST API dispatch servlets. And dispatch servlets for the UI APP itself.
Can you indicate what servlet(s) you are referring too? As the configuration can be different.

Yvo

There is class called FlowableServlet whose loadOnStartup is -1 meaning , intentionally made it to execute on first api call . I want to know what is benefit of making it on first api call and if the servlet loading happen through first api call , then it will be performance impact and overall average of api response will change

Hi,

You can configure the initialisation behaviour of the REST dispatch servlets by setting this property;

flowable.<engine>.servlet.load-on-startup

so for example;

flowable.process.servlet.load-on-startup=1

will initialise the BPMN REST API eagerly.

Have a look here for the available properties;

But; I’m not convinced of the fact this will give a noticeable performance benefit. The lazy init of the servlet dispatcher will add a minor performance impact on the first API request. But only the first. In my opinion a negligible impact looking at the total execution time when executing multiple requests.

Yvo

Thanks @yvo for the quick response.
Please help me in one of another doubt ,
If i make changes suggested by you , after that, is there will be issue in future ?
Or Is there any benefit of default behavhour that is loading servlet at the first api call ?
Or both behaviour is fine (eager and lazy)?

Mohit

With changes you mean setting certain properties?
I don’t see any issues now or in the foreseeable future.
Both behaviour is fine. There are marginal differences. Which approach is best depends on your use case.

Thank you @yvo for clarifying doubts , it will help me