package mythread;

public class Timer implements Runnable {
	private Thread t; //定义一个线程
	@Override
	public void run() {
		try {
			for (int i = 10; i > 0; i--) {
				System.out.println( i);
				// 让线程睡眠一会
				Thread.sleep(1000);//每隔1s执行一次循环
			}
		} catch (InterruptedException e) {
			System.out.println("Thread  interrupted.");
		}

	}

	public static void main(String[] args) {
		Timer timer = new Timer();
		timer.run();
	}
}

编写一个定时器(通过实现Runnable 接口)

相关文章:

  • 2021-11-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-06
猜你喜欢
  • 2022-12-23
  • 2022-02-19
  • 2022-02-19
  • 2021-08-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案