Java

자바의신 ch25

langsamUndStetig 2022. 7. 7. 17:03
package e.thread.practice;

import java.util.Date;

public class TimerThread extends  Thread {
  public void run() {
    printCurrentTime();
  }
  public void printCurrentTime() {
    int count=0;
    while(count<10) {
      System.out.println(new Date() + " "+ (System.currentTimeMillis() - System.currentTimeMillis() %1000 ));
      try{
      Thread.sleep(1000);}
      catch(InterruptedException ie) {
        ie.printStackTrace();
      }
      count++;
    }

  }
}
package e.thread.practice;

public class TimerMain {
  public static void main(String[] args) {
    TimerThread sample = new TimerThread();
    sample.printCurrentTime();
  }
}