多线程写时钟
package com.test; import java.text.SimpleDateFormat; import java.util.Date; public class Thread1 extends Thread{ SimpleDateFormat sdf=new SimpleDateFormat("HH:mm:ss"); @Override public void run() { while (true){ try { System.out.println(sdf.format(new Date())); sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } } }
package com.test; public class Main { public static void main(String[] args) { Thread1 thread1= new Thread1(); thread1.start(); } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)