在纯java应用中如何使用c3po?( 没有框架,没有tomcat)

2023-05-28 综合 27阅读
定时问题 ORACLE 有作业来实现的不用写到项目里,如果非要用java 还不用框架来弄的话可以考虑下

在xml中配置监听
<listener-class>com.timer.MyListener</listener-class>
<困知/listener>汪稿消
<listener>
<listener-class>com.IMS.ImsListener</listener-class>
</listener>

import java.util.Timer;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class MyListener implements ServletContextListener {

private Timer timer = null;

public void contextInitialized(ServletContextEvent event) {
timer = new Timer(true);
//调用执行类设置任务计划,启动和间隔时间
timer.schedule(new MyTask(), 10000, 30000);
}

public void contextDestroyed(ServletContextEvent event) {
timer.cancel();
}

}

//执行类
import java.util.TimerTask;
public class MyTask extends TimerTask {

@Override
public void run() {
// TODO Auto-generated method stub

System.out.println("1113");

}

}

package com.timer;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.TimerTask;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.olive.sebb.wlbqz.domain.SebbWlbqz;
import com.olive.sebb.wlbqz.service.WlbqzService;
import com.olive.sebb.wlbqz.service.WlbqzServiceImpl;
import com.opensymphony.webwork.ServletActionContext;
//敬汪执行定时任务
public class MyTask extends TimerTask {

@Override
public void run() {
// TODO Auto-generated method stub

System.out.println("1113");

}

}
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com