package com.ajah.thread;

import java.util.logging.Level;
import java.util.logging.Logger;

import com.ajah.util.date.CalendarUnit;

/*
 *  Copyright 2012 Eric F. Savage, code@efsavage.com
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */

/**
 * Utilities for dealing with threads and multithreading.
 * 
 * @author <a href="http://efsavage.com">Eric F. Savage</a>, <a
 *         href="mailto:code@efsavage.com">code@efsavage.com</a>.
 * 
 */
public class ThreadUtils {

	private static final Logger log = Logger.getLogger(ThreadUtils.class.getName());

	/**
	 * Sleep via {@link #sleep(long)} for the specified length of time.
	 * 
	 * @param quantity
	 *            The quantity of the specified unit.
	 * @param calendarUnit
	 *            The unit of time the quantity represents.
	 */
	public static void sleep(final int quantity, final CalendarUnit calendarUnit) {
		sleep(quantity * calendarUnit.getMillis());
	}

	/**
	 * Sleep for the specified number of ms. If interuppted by
	 * {@link InterruptedException}, just return.
	 * 
	 * @param ms
	 *            The number of ms to sleep, must be 0 or greater.
	 */
	public static void sleep(final long ms) {
		try {
			Thread.sleep(ms);
		} catch (final InterruptedException e) {
			log.log(Level.FINE, e.getMessage(), e);
		}
		return;
	}

}

@@ -1622,28 +1622,41 @@
 ep, 
-must be 0 or greater
+if 0 or less, returns immediately
 .%0A%09 
@@ -1701,16 +1701,48 @@
 g ms) %7B%0A
+%09%09if (ms %3C= 0) %7B%0A%09%09%09return;%0A%09%09%7D%0A
 %09%09try %7B%0A

Add short-circuit