建立一个每隔10秒执行的线程

//线程类
public class TestThread extends Thread {
    public void run() {
        while(true){
            try {
                sleep(6*1000);
                                //这里可以写你自己要运行的逻辑代码
                System.out.println("一分钟运行一次");
            catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
             
        }
    }
}
//运行线程类MAIN
public class TestThreadMain {
 
    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        TestThread testThread = new TestThread();
        testThread.start();
    }
 
}
posted @ 2017-12-03 11:44  baby孔祥超  阅读(3041)  评论(0编辑  收藏  举报