download:Details on performance monitoring and tuning in Java production environment
This course will show you how to monitor and tune the performance of Java applications in a production environment. Through this course, you will learn how to use various performance monitoring tools to locate and solve problems such as memory overflow and CPU load surge. Learn online code debugging, Tomcat, Nginx, GC tuning and other means; Read JVM bytecode instructions, analyze the principle behind the source code, and improve the ability to deal with online emergencies
Suitable for people with at least one project development and online experience students who want to learn how to apply monitoring and tuning techniques in production environment students who want to improve their ability to solve various performance problems in production environment students who are preparing to advance to senior engineer in Java
Technical background: Java,Linux,Tomcat,Nginx and other Java junior and intermediate engineers are required
<listener-class>org.springframework.web.context.ContextLoaderListener
<servlet-name>dispatcher
<servlet-class>org.springframework.web.servlet.DispatcherServlet
<init-param>
<param-name>contextConfigLocation
<param-value>classpath*:spring-mvc.xml
<load-on-startup>1
<servlet-mapping>
<servlet-name>dispatcher
<url-pattern>/*
Copy the code
So you can see that we’ve configured the ContextLoaderListener, it’s done ServletContextListener, it’s configured this listener in the XML, and when you start the container, it’s automatically done contextInitialized(),
The central logic in the ServletContextListener is to initialize the WebApplicationContext instance and store it in the ServletContext, So we just need to get the Servlet to get the WebApplicationContext object and apply it to access the Spring container-managed beans.
public void contextInitialized(ServletContextEvent event) { initWebApplicationContext(event.getServletContext()); } public WebApplicationContext initWebApplicationContext(ServletContext servletContext) { if (servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE) ! = null) { throw new IllegalStateException( “Cannot initialize context because there is already a root application context present – ” + “check whether you have multiple ContextLoader* definitions in your web.xml!” ); } servletContext.log(“Initializing Spring root WebApplicationContext”); Log logger = LogFactory.getLog(ContextLoader.class); if (logger.isInfoEnabled()) { logger.info(“Root WebApplicationContext: initialization started”); } long startTime = System.currentTimeMillis(); try { // Store context in local instance variable, To guarantee that // it is available on ServletContext shutdown. Is the ioc container / / createWebApplicationContext finally return values are forced into ConfigurableWebApplicationContext type if (enclosing context = = null) { this.context = createWebApplicationContext(servletContext); } the if (enclosing context instanceof ConfigurableWebApplicationContext) {/ / forced into ConfigurableWebApplicationContext ConfigurableWebApplicationContext cwac = (ConfigurableWebApplicationContext) this.context; // CWAC has not yet been activated and has not stopped loading configuration files. cwac.isActive()) { // The context has not yet been refreshed -> provide services such as // setting the parent context, setting the application context id, etc if (cwac.getParent() == null) { // The context instance was injected without an explicit parent -> // determine parent for root web application context, if any. ApplicationContext parent = loadParentContext(servletContext); cwac.setParent(parent); } / / load the configuration file, that is, the configuration of the applicationContext. XML file configureAndRefreshWebApplicationContext (cwac, servletContext); }} // Set ioc to my parent so that the child can access the parent, But the parent container (IOC container) cannot access the child container (DispatcherServlet) servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.context); ClassLoader ccl = Thread.currentThread().getContextClassLoader(); if (ccl == ContextLoader.class.getClassLoader()) { currentContext = this.context; } else if (ccl ! = null) { currentContextPerThread.put(ccl, this.context); } if (logger.isInfoEnabled()) { long elapsedTime = System.currentTimeMillis() – startTime; logger.info(“Root WebApplicationContext initialized in ” + elapsedTime + ” ms”); } return this.context; } catch (RuntimeException | Error ex) { logger.error(“Context initialization failed”, ex); servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ex); throw ex; } then start by initializing the DispatcherServlet, which completes the Servlet interface,
public interface Servlet {
/**
- The container is called when it is started (when load-on-startup is negative or not set, it is called the first time it is used) and only once
- It takes a parameter, ServletConfig, which is passed in by the container to represent some configuration of the Servlet, */ public void init(ServletConfig config) throws ServletException. / * *
- Public ServletConfig getServletConfig(); / * *
- The most important one, Public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException; void service(ServletRequest req, ServletResponse res) throws ServletException, IOException; / * *
- Public String getServletInfo(); public String getServletInfo(); / * *
- */ public void destroy(); */ public void destroy(); } init method begins to initialize the container