All Downloads are FREE. Search and download functionalities are using the official Maven repository.

panda.lang.Threads Maven / Gradle / Ivy

Go to download

Panda Core is the core module of Panda Framework, it contains commonly used utility classes similar to apache-commons.

There is a newer version: 1.8.0
Show newest version
package panda.lang;

public class Threads {
	/**
	 * start a runnable and return the thread object
	 * @param r a runnable object
	 * @return thread object
	 */
	public static Thread start(Runnable r) {
		Thread t = new Thread(r);
		t.start();
		return t;
	}
	
	/**
	 * start a runnable and return the thread object
	 * @param r a runnable object
	 * @param name thread name
	 * @return thread object
	 */
	public static Thread start(Runnable r, String name) {
		Thread t = new Thread(r, name);
		t.start();
		return t;
	}

	/**
	 * join, do not throw exception
	 * 
	 * @param t the thread
	 */
	public static void safeJoin(Thread t) {
		try {
			t.join();
		}
		catch (InterruptedException e) {
		}
	}
	
	/**
	 * sleep, do not throw exception
	 * @param ms milliseconds
	 */
	public static void safeSleep(long ms) {
		try {
			Thread.sleep(ms);
		}
		catch (InterruptedException e) {
		}
	}
	
	
	/**
	 * wait, do not throw exception
	 * @param obj the wait object
	 * @param ms milliseconds
	 */
	public static void safeWait(Object obj, long ms) {
		try {
			obj.wait(ms);
		}
		catch (InterruptedException e) {
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy