package com.robert.thread;import java.util.Date;public class TestThreadSleep implements Runnable{ public static void main(String[] args) { TestThreadSleep runnable = new TestThreadSleep(); Thread thread = new Thread(runnable); thread.start(); } @Override public void run() { System.out.println("i am sleep for a while!"); try { Date currentTime = new Date(); long startTime = currentTime.getTime(); Thread.sleep(4000); currentTime = new Date(); long endTime = currentTime.getTime(); System.out.println("休眠时间为:"+(endTime-startTime)+"ms"); } catch (InterruptedException e) { e.printStackTrace(); } }}