public class DeferredInitDelegatingServlet
extends javax.servlet.http.HttpServlet
This delegating servlet with 'deferring initialization' feature can be useful if you want to start a web application fast enough without waiting for a servlet initialization to complete. For example, when you deploy spring boot based web application(s) onto a cloud based platform, you don't have to worry about the timeout issue (e.g, 60 seconds by default somewhere) due to a long time initializing servlet.
For example, suppose you have a servlet that may take long time to initialize itself like the following:
<servlet> <servlet-name>LongTimeInitServlet</servlet-name> <servlet-class>org.example.LongTimeInitServlet</servlet-class> <load-on-startup>100</load-on-startup> </servlet>You can change the
servlet-class
to org.onehippo.forge.hipshoot.spring.boot.support.servlet.DeferredInitDelegatingServlet
and provide the real delegate servlet class name in the DeferredInitDelegatingServlet.delegateServletClass
init parameter instead like the following example:
<servlet> <servlet-name>LongTimeInitServlet</servlet-name> <servlet-class>org.onehippo.forge.hipshoot.spring.boot.support.servlet.DeferredInitDelegatingServlet</servlet-class> <init-param> <param-name>DeferredInitDelegatingServlet.delegateServletClass</param-name> <param-value>org.example.LongTimeInitServlet</param-value> </init-param> <load-on-startup>100</load-on-startup> </servlet>
Then this servlet class will pass the servlet initialization phase fast because the real initialization of the delegate servlet will be done asynchronously so that the servlet container may start all the other web applications faster without having to wait for the delegate servlet to complete the initialization phase.
Constructor and Description |
---|
DeferredInitDelegatingServlet() |
Modifier and Type | Method and Description |
---|---|
void |
destroy() |
void |
init(javax.servlet.ServletConfig servletConfig) |
void |
service(javax.servlet.ServletRequest req,
javax.servlet.ServletResponse res) |
doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service
public void init(javax.servlet.ServletConfig servletConfig) throws javax.servlet.ServletException
init
in interface javax.servlet.Servlet
init
in class javax.servlet.GenericServlet
javax.servlet.ServletException
public void destroy()
destroy
in interface javax.servlet.Servlet
destroy
in class javax.servlet.GenericServlet
public void service(javax.servlet.ServletRequest req, javax.servlet.ServletResponse res) throws javax.servlet.ServletException, IOException
service
in interface javax.servlet.Servlet
service
in class javax.servlet.http.HttpServlet
javax.servlet.ServletException
IOException
Copyright © 2019. All rights reserved.