package com.xuexi;
import java.util.Date;
//Java 休眠(sleep)
//sleep()使当前线程进入停滞状态(阻塞当前线程),让出CPU的使用、目的是不让当前线程独自霸占该进程所获的CPU资源,以留一定时间给其他线程执行的机会。
public class Time3 {
public static void main(String[] args) {
try {
// 测量时间间隔
long start = System.currentTimeMillis();
System.out.println(new Date()+" ");
Thread.sleep(1000*3);
System.out.println(new Date()+" ");
long end = System.currentTimeMillis();
long diff =end - start;
System.out.println("时间间隔"+diff);
}catch (Exception e){
System.out.println("");
}
}
}