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, if 0 or less, returns immediately.
	 */
	public static void sleep(final long ms) {
		if (ms <= 0) {
			return;
		}
		try {
			Thread.sleep(ms);
		} catch (final InterruptedException e) {
			log.log(Level.FINE, e.getMessage(), e);
		}
		return;
	}

}

@@ -1,137 +1,4 @@
-package com.ajah.thread;%0A%0Aimport java.util.logging.Level;%0Aimport java.util.logging.Logger;%0A%0Aimport com.ajah.util.date.CalendarUnit;%0A%0A
 /*%0A 
@@ -14,16 +14,21 @@
 ght 2012
+-2014
  Eric F.
@@ -633,16 +633,148 @@
 nse.%0A */
+%0Apackage com.ajah.thread;%0A%0Aimport java.util.logging.Level;%0Aimport java.util.logging.Logger;%0A%0Aimport com.ajah.util.date.CalendarUnit;
 %0A%0A/**%0A *
@@ -1870,10 +1870,343 @@
 rn;%0A%09%7D%0A%0A
+%09/**%0A%09 * Sleeps until a set time. If the time is in the pass, no sleep occurs.%0A%09 * %0A%09 * @param timestamp%0A%09 *            The timestamp when the sleep should terminate.%0A%09 */%0A%09public static void sleepUntil(final long timestamp) %7B%0A%09%09if (System.currentTimeMillis() %3C timestamp) %7B%0A%09%09%09sleep(timestamp - System.currentTimeMillis());%0A%09%09%7D%0A%09%7D%0A%0A
 %7D%0A

Add sleepUntil