/* * Copyright (c) Michael Thomas, All Rights Reserved. (michael@michael-thomas.com) * * Permission to use, copy, modify, and distribute this software * and its documentation for NON-COMMERCIAL purposes and without * fee is hereby granted provided that this copyright notice * appears in all copies. Exceptions must be in writing between the * copyright holder and entity using the content. * * THE COPYRIGHT HOLDER MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. */ /** * @author Michael Thomas * @version 1.0 07/04/08 */ package firststeps; import java.util.Date; public class ThreadsHelloWorldSleepSimple { public static void main(String args[]) throws InterruptedException { String strThreadName = Thread.currentThread().getName(); int intLoopCount = 5; System.out.println(strThreadName + " - Start Time - " + (new Date()).toString()); for (int i = 1; i <= intLoopCount; i++) { //Pause for 2 seconds. //Sleep can throw and exception we throw it up in the main() method. Thread.sleep(2 * 1000); System.out.println(strThreadName + " - Hello World #" + i + " - " + (new Date()).toString()); } System.out.println(strThreadName + " - before 4 second sleep - " + (new Date()).toString()); Thread.sleep(4 * 1000); System.out.println(strThreadName + " - after 4 second sleep - " + (new Date()).toString()); System.out.println(strThreadName + " - Stop Time - " + (new Date()).toString()); } }