系统加载配置文件 跟 定时跑批

系统加载配置文件 和 定时跑批

import java.util.Calendar;

import java.util.Date;

import java.util.Timer;

import javax.servlet.http.HttpServlet;

import org.apache.log4j.Logger;

/**

 * 系统加载

 * @date 2011-06-08

 */

@SuppressWarnings("serial")

public class Init extends HttpServlet {

public static Logger logger = Logger.getLogger(Init.class);

@SuppressWarnings("static-access")

public void init() 

{

logger.error("admin start...");

String classespath = getServletContext().getRealPath("/WEB-INF/classes/config");

try 

{

//读取codes.properties

starterimpl.loadCodes(classespath);

//读取init.properties

starterimpl.loadInits(classespath);


//定时凌晨1点跑批

Timer timer = new Timer();

TimeService timeService = new TimeService();

Calendar cd = Calendar.getInstance();

cd.setTime(new Date());

//设置开始时间为明天凌晨1点

cd.add(Calendar.DAY_OF_MONTH, 1);

cd.set(Calendar.HOUR_OF_DAY, 1);

cd.set(Calendar.MINUTE, 0);

cd.set(Calendar.SECOND, 0);

//在延迟 delay 秒后执行 mytask

long delay = (cd.getTime()).getTime() - (new Date()).getTime();

//执行周期为一天

timer.schedule(timeService, delay, 24 * 60 * 60 * 1000);

logger.error("admin success...");

catch (Exception e) 

{

e.printStackTrace();

logger.error("admin error...");

}

}

}

********************************------------------------------------------

public class InitImpl 
{


public static Logger logger = Logger.getLogger(InitImpl.class);

/**加载 codes.properties的内容 path访问根路径*/
public static void loadCodes(String path) throws IOException
{
path = path + "/codes.properties";

        if (FileHelper.exists(path))

        {

        Main.codes = FileHelper.readPropertiesFile(path);

        } 

        else 

        {

        logger.error("admin code.properties not loaded");

        }

}
/**加载 init.properties的内容 path访问根路径*/
public static void loadInits(String path) throws IOException
{
path = path + "/init.properties";

        if (FileHelper.exists(path))

        {

        Properties pro = FileHelper.readPropertiesFile(path);

        Main.rootpath = pro.getProperty("rootpath");

        Main.homepath = pro.getProperty("homepath");

        Main.picpath = pro.getProperty("picpath");

        Main.ippath = pro.getProperty("winekeeip");

        Main.winekeeurl = pro.getProperty("winekeeurl");

        Main.inits = pro;

        } 

        else 

        {

        logger.error("admin init.properties not loaded");

        }

}

}

#####################*************************************


public class TimeService  extends  TimerTask
{
public static Logger logger = Logger.getLogger(TimeService.class);

@Override
public void run() 
{
logger.error("timertask start...");

logger.error("timertask end...");
}

}