在线等listener的问题
web.xml里加上一句
<listener>
<listener-class>
com.smartone.sn.nsms.emailthread.EmailMonitoring
</listener-class>
</listener>
com.smartone.sn.nsms.emailthread.EmailMonitoring.java:
package com.smartone.sn.nsms.emailthread;
import java.util.Properties;
import java.util.Timer;
import java.util.TimerTask;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import
org.apache.log4j.Logger;
public class EmailMonitoring implements ServletContextListener {
Logger logger = Logger.getLogger(EmailMonitoring.class);
private static Timer timer = new Timer(true);
/**
* @see ServletContextListener#contextInitialized(ServletContextEvent)
*/
static final String MAIL_CHECKING_INTERVAL = "email-checking-interval";
static final String MAIL_CONFIG_FILE = "email-config-file";
static final int ONE_SECOND = 1000;
static final int ONE_MINUTE = 60 * ONE_SECOND;
static final int ONE_HOUR = 60 * ONE_MINUTE;
public void contextInitialized(ServletContextEvent arg0) {
// TODO Auto-generated method stub
// Enumeration e = arg0.getServletContext().getInitParameterNames();
//
// while (e.hasMoreElements()) {
// System.out.println(e.nextElement().toString());
// }
int checkingInterval = Integer.parseInt(arg0.getServletContext()
.getInitParameter(MAIL_CHECKING_INTERVAL));
String mailConfigFilename = arg0.getServletContext().getInitParameter(
MAIL_CONFIG_FILE);
String mailhost = arg0.getServletContext().getInitParameter(
"email-pop3-host");
String alert2system = arg0.getServletContext().getInitParameter(
"email-pop3-user");
String mailpassword = arg0.getServletContext().getInitParameter(
"email-pop3-password");
// timer = new Timer(true);
Properties prop = new Properties();
prop.put("mail.pop3.user", alert2system);
prop.put("mail.pop3.password", mailpassword);
prop.put("mail.pop3.host", mailhost);
prop.put("mail.pop3.disabletop", "true");
// try {
// prop.load(new FileInputStream(mailConfigFilename));
// } catch (Exception ex) {
// logger.error("error when loading properties file", ex);
// }
TimerTask task = new CheckMailTimerTask(prop);
timer.scheduleAtFixedRate(task, ONE_MINUTE, checkingInterval);
}
/**
* @see ServletContextListener#contextDestroyed(ServletContextEvent)
*/
public void contextDestroyed(ServletContextEvent arg0) {
// TODO Auto-generated method stub
timer.cancel();
}
}
报错:
SEVERE: Exception sending context initialized event to listener instance of class com.smartone.sn.nsms.emailthread.EmailMonitoring
java.lang.NumberFormatException: null at java.lang.Integer.parseInt(Integer.java:417)
at java.lang.Integer.parseInt(Integer.java:499)
at com.smartone.sn.nsms.emailthread.EmailMonitoring.contextInitialized(Unknown Source)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4135)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4630)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.a