Home > Java > javaTutorial > body text

Java's Timer and TimerTask simple demo (share)

高洛峰
Release: 2017-01-11 15:55:41
Original
1137 people have browsed it

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);
    }
}
Copy after login

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+"秒");
    }
     
}
Copy after login

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!


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template