日期:2014-05-17 浏览次数:20794 次
public class Myclock extends HttpServlet{ public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException{ String fun = request.getParameter("fun"); ServletContext application=getServletContext(); request.setAttribute("fun", fun); Date date=null; DateFormat df=new SimpleDateFormat("yyyyMMddHHmmss"); String str="2012509161000"; try { date=df.parse(str); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } if(fun.equals("1")){ //fun是前台JSP传递过来的值,用于判断是否是手动开启timer或关闭 Timer timer=new Timer(); [color=#FF0000] timer.schedule(new MyTask(),date,5*60*1000L);[/color] application.setAttribute("timer",timer); request.getRequestDispatcher("/jsp/administer/delData.jsp").forward(request,response) ; }else{ Timer timer = (Timer)application.getAttribute("timer"); timer.cancel(); application.setAttribute("timer", null); request.getRequestDispatcher("/jsp/administer/delData.jsp").forward(request,response) ; } } public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException{ doGet(request,response); } }
public void run() { a++; System.out.println("***********************a==="+a+"**************************************"); GetdateFormat time1 = new GetdateFormat(); Timestamp time_now = time1.getDatetime(); System.out.println("现在时间是:"+time_now+"============"); Long oneday = 24*60*60*1000L; Timestamp time = new Timestamp(time_now.getTime()-oneday); List <FeedData> feedData = feedDataDao.getAllFeedDaoBeforeTime(time); int amount=feedData.size(); if(amount!=0){ for(int i=0;i<amount+1;i++){ ; feedDataDao.delete(feedData.get(i)); amount--; System.out.println("amount===="+amount); FeedData temp = feedData.get(i); //将删除的数据存入del_data_bck表中 DelDataBackup del_data = new DelDataBackup(); del_data.setFeedDatastream(temp.getFeedDatastream()); del_data.setCvfdsdata_bck(temp.getCvfdsdata()); del_data.setCddsdatatime_bck(temp.getCddsdatatime()); System.out.println("del_data====="+del_data); delDataB