package timer;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Timer;
import java.util.TimerTask; import util.DBUtil; public class TimerTest {
public static void main(String[] args) {
Timer timer = new Timer();
// 延迟1秒钟,每5秒钟执行一次
timer.schedule(new MyTask(), 1000, 5000);
}
} class MyTask extends TimerTask{ // 任务内容
@Override
public void run() {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
conn = DBUtil.getConnection();
String sql = "select status from jiankong_table where service_name='duomeidai-web' and "
+ "service_time = DATE_FORMA(NOW(),'%Y-%m-%d') order by service_time desc limit 1";
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while(rs.next()){
System.out.println(rs.getInt("status"));
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
DBUtil.close(conn, stmt, rs);
}
}
}

以上先睹为快。

如果使用TimerTask或者定时任务,后续进行补贴!

使用Java的Timer处理周期性任务的更多相关文章

  1. 使用java.util.Timer来周期性的执行制定的任务

    使用java.util.Timer来周期性的执行制定的任务 public class HandlerTest extends Activity { int[] images = new int[] { ...

  2. java关于Timer schedule执行定时任务 1、在应用开发中,经常需要一些周期性的操作,比如每5分钟执行某一操作等

    1.在应用开发中,经常需要一些周期性的操作,比如每5分钟执行某一操作等.对于这样的操作最方便.高效的实现方式就是使用java.util.Timer工具类. private java.util.Time ...

  3. Java定时任务Timer、TimerTask与ScheduledThreadPoolExecutor详解

     定时任务就是在指定时间执行程序,或周期性执行计划任务.Java中实现定时任务的方法有很多,本文从从JDK自带的一些方法来实现定时任务的需求. 一.Timer和TimerTask  Timer和Tim ...

  4. java关于Timer schedule执行定时任务 !!!!!!!!!

    1.在应用开发中,经常需要一些周期性的操作,比如每5分钟执行某一操作等.对于这样的操作最方便.高效的实现方式就是使用java.util.Timer工具类. private java.util.Time ...

  5. Java基础复习--java.util.Timer定时任务

    在java中,Timer类主要用于定时性.周期性任务 的触发,这个类中有两个方法比较难理解,那就是schedule和scheduleAtFixedRate方法,在这里就用实例分析一下. (1)sche ...

  6. Java定时器Timer

    Java定时器Timer在JDK库中,Timer类主要负责计划任务的功能,也就是在指定的时开始执行某一个任务.Timer类的主要作用就是设置计划任务,但封装任务的类却是TimerTask类,执行计划任 ...

  7. Java中Timer的用法

    现在项目中用到需要定时去检查文件是否更新的功能.timer正好用于此处. 用法很简单,new一个timer,然后写一个timertask的子类即可. 代码如下: package comz.autoup ...

  8. java之Timer

    一.Java2的开发包中提供了一种很好使用的线程功能:你可以使用这些类创建后台进程,让其在等待一段规定的时间后执行,或者让其每隔一段时间执行.你也可以用Thread来完成,但利用Timer与Timer ...

  9. Java计时器Timer和TimerTask用法

    package com.sy.game.test; import java.util.Timer; import java.util.TimerTask; public class TimeTask ...

随机推荐

  1. PHP 爬虫

    1.爬虫的本质简单来说,就是读取页面源代码,然后用正则匹配得到想要的数据. 示例如下: private function spider_jiuyou_list($listname,$url)    { ...

  2. 01-04 Json和弹窗

    //JSON是一种数据格式//JSON比较像php里面的关联数组,它里面存的内容也是key和value成对存在的 </body><script type="text/jav ...

  3. linux驱动之LCD

    LCD程序步骤:1. 分配一个fb_info 2. 设置 3. 硬件相关的操作4. 注册 register_framebuffer 5.入口函数 6.出口函数 #include <linux/s ...

  4. MVC 从后台页面 取前台页面传递过来的值的几种取法

      MVC 从后台页面 取前台页面传递过来的值的几种取法   <1>前台页面 Index视图 注意:用户名表单的name值为txtName 密码表单的name值为txtPassword & ...

  5. gridView RowDataBound事件 鼠标经过行颜色变化及根据字段值显示指定内容

    protected void gvBarInfo_RowDataBound(object sender, GridViewRowEventArgs e)        {            if ...

  6. Mongodb在Linux下安装及配置

    1.下载mongodb的linux版本(注意32位和64位的区别),下载地址:http://www.mongodb.org/downloads 2.将下载的mongodb安装文件mongodb-lin ...

  7. B - I Hate It

    #include<cstdio> #include<string.h> using namespace std; int ans; ; ]; struct Node{ int ...

  8. pysproto bug修复

    最近,找隔壁组的同学测试了一下我的pysproto,他们提了很多有益的建议,非常感谢. 在测试中,出现了一次诡异的coredump.当数据变大的时候,就有很大的机率遇上double free.在spr ...

  9. imshow() displays a white image for a grey image

    Matlab expects images of type double to be in the 0..1 range and images that are uint8 in the 0..255 ...

  10. CSS背景色渐变

      试了下 渐变色  ,主要确定开始位置  结束位置,以及对应的color-stop;  以下是兼容不同浏览器的代码片段       代码:<style type="text/css& ...