/* * Copyright@ 2011 www.egtry.com */ package egtry.thread; import java.util.Date; //suspect the execution of the current thread for certain period of time (millisecond) public class Sleep { public static void main(String[] args) { System.out.println("Start the program at: "+new Date()); try { Thread.sleep(3*1000); //sleep for 3 seconds } catch (Exception e) { System.out.println("the sleeping was interrupted"); } System.out.println("Done at: "+new Date()); } }
Start the program at: Mon Oct 03 11:37:48 CDT 2011 Done at: Mon Oct 03 11:37:51 CDT 2011