java 之 load-on-startup 的詳解

The load-on-startup element indicates that this servlet should be loaded (instantiated and have its init() called) on the startup of the web application. The optional contents of these element must be an integer indicating the order in which the servlet should be loaded. If the value is a negative integer, or the element is not present, the container is free to load the servlet whenever it chooses.  If the value is a positive integer or 0, the container must load and initialize the servlet as the application is deployed. The container must guarantee that servlets marked with lower integers are loaded before servlets marked with higher integers. The container may choose the order of loading of servlets with the same load-on-start-up value.


load-on-startup 元素在web應用啓動的時候指定了servlet被加載的順序,它的值必須是一個整數。如果它的值是一個負整數或是這個元素不存在,那麼容器會在該servlet被調用的時候,加載這個servlet。如果值是正整數或零,容器在配置的時候就加載並初始化這個serlvet,容器必須保證值小的優先加載。如果數值相等,容器可以自動選擇先加載。

 

package com.sample.base;

import java.io.File;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import org.apache.log4j.Logger;

public class Boot extends HttpServlet {
	
	private static final long serialVersionUID = 4177925985208589275L;
	private static final Logger logger = Logger.getLogger(Boot.class);

	@Override
	public void init(ServletConfig config) throws ServletException {
		super.init(config);
		logger.info("Server booting...");
		logger.info("OS Name:" + System.getProperty("os.name"));
		logger.info("OS Version:" + System.getProperty("os.version"));
		logger.info("OS Architecture:" + System.getProperty("os.arch"));
		logger.info("CPU Maybe:" + System.getProperty("sun.cpu.isalist"));
		logger.info("JRE Version:" + System.getProperty("java.version"));
		logger.info("JRE Runtime:" + System.getProperty("java.runtime.version"));
		java.net.URL url = getClass().getClassLoader().getResource("/");
		String SERVER_PATH = new File(url.getPath()).getParent() + File.separator;
		logger.info("SERVER_PATH:" + SERVER_PATH);
		try {
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public void destroy() {
		super.destroy();
	}

}
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章