servlet定时任务

  • Post author:
  • Post category:其他


public void init() throws ServletException {

final ServletContext sc = this.getServletContext();

ApplicationContext ac = WebApplicationContextUtils

.getWebApplicationContext(sc);

smsdao = (SmstDao) ac.getBean(“smsdao”);

String smsTemp = this.getInitParameter(“smsTemp”);//是否扫描

if(“1”.equals(smsTemp)){

Timer smstempTimer = new Timer(true);

smstempTimer.schedule(new TimerTask(){

public void run(){

try{

List<String> smsList = new ArrayList<String>();

String ids = “”;

//查询

smsList = smsdao.scanSmsTemp();

//插入

smsdao.sendSmsTemp(ids);

smsdao.updateSmsTemp(ids);

}catch(Exception e){

e.printStackTrace();

}

}

},0, 1000 * 30);

}

}

======================================

web.xml

=====================================

<servlet>

<servlet-name>SmsSender</servlet-name>

<servlet-class>com.besys.platform.servlet.SmsSender</servlet-class>

<init-param>

<param-name>smsTemp</param-name>

<param-value>1</param-value>

</init-param>

<load-on-startup>1</load-on-startup>

</servlet>



版权声明:本文为u011433170原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。