【Java】【Thread多线程】Timer类

2017-04-08  本文已影响13人  JerichoPH

Timer类

```
public class Demo {
    public static void main(String[] args) throws IOException, InterruptedException {
        Timer t = new Timer();
        t.schedule(new MyTimerTask(), new Date(117, 1, 4, 8, 28, 45));
        
        new Thread(){
            @Override
            public void run() {
                while(true){
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(new MyDatetime(System.currentTimeMillis()).getCn());
                }
            }
        }.start();
    }
}

class MyTimerTask extends TimerTask {
    @Override
    public void run() {
        System.out.println("这里是闹钟");
    }
}
```
上一篇 下一篇

猜你喜欢

热点阅读