Home  >  Article  >  Java  >  Java's Timer and TimerTask simple demo (share)

Java's Timer and TimerTask simple demo (share)

高洛峰
高洛峰Original
2017-01-11 15:55:411134browse

Code: Test class

public class MyTestTimer {
    public static Timer mTimer;
    public static void main(String[] args) {
        mTimer=new Timer();
        MyTimerTask testTimer=new MyTimerTask(10000);
        mTimer.schedule(testTimer, 10000);
    }
}

TimerTask task class

public class MyTimerTask extends TimerTask{
    private int second;
    public MyTimerTask(int second) {
        this.second=second;
    }
    public void run() {
        System.out.println("我等你等了"+second+"秒");
    }
     
}

The above simple demo (sharing) of Timer and TimerTask in java is The editor has shared all the content with you. I hope it can give you a reference. I also hope that everyone will support the PHP Chinese website.

For more Java Timer and TimerTask simple demo (sharing) related articles, please pay attention to the PHP Chinese website!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn