Package de.mhus.lib.core
Class MThread
- java.lang.Object
-
- de.mhus.lib.core.MLog
-
- de.mhus.lib.core.lang.MObject
-
- de.mhus.lib.core.MThread
-
- All Implemented Interfaces:
ILog,MNlsProvider,Nls,Runnable
- Direct Known Subclasses:
MThreadDaemon
public class MThread extends MObject implements Runnable
- Author:
- hummel To change the template for this generated type comment go to Window>Preferences>Java>Code Generation>Code and Comments
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidasynchron(Runnable task)static <T> TgetAsynchronWithTimeout(ValueProvider<T> provider, long timeout)Calls the provider once and will return the result.static <T> TgetAsynchronWithTimeout(ValueProvider<T> provider, long timeout, boolean nullAllowed)Like getWithTimeout but executed in a separate task, this means unblocking.protected ThreadGroupgetGroup()StringgetName()intgetPriority()protected RunnablegetTask()ThreadgetThread()static <T> TgetWithTimeout(ValueProvider<T> provider, long timeout, boolean nullAllowed)Try every 200ms to get the value.protected voidinitThread(Thread thread)voidinterupt()voidrun()voidsetName(String _name)voidsetPriority(int _p)static voidsleep(long _millisec)Sleeps _millisec milliseconds.MThreadstart()voidstop()protected voidtaskError(Throwable t)StringtoString()static voidwaitFor(Checker checker, long timeout)Wait for the checker to return true or throw an TimeoutRuntimeException on timeout.static voidwaitForWithException(Checker checker, long timeout)Wait for the checker to return true or throw an TimeoutRuntimeException on timeout.
-
-
-
Method Detail
-
getTask
protected Runnable getTask()
-
start
public MThread start()
-
getGroup
protected ThreadGroup getGroup()
-
initThread
protected void initThread(Thread thread)
-
setName
public void setName(String _name)
-
getName
public String getName()
-
setPriority
public void setPriority(int _p)
-
getPriority
public int getPriority()
-
stop
public void stop()
-
interupt
public void interupt()
-
sleep
public static void sleep(long _millisec)
Sleeps _millisec milliseconds. On Error (e.g. a break), it prints a stacktrace dump.- Parameters:
_millisec-
-
taskError
protected void taskError(Throwable t)
-
asynchron
public static void asynchron(Runnable task)
-
getWithTimeout
public static <T> T getWithTimeout(ValueProvider<T> provider, long timeout, boolean nullAllowed)
Try every 200ms to get the value. If the provider throws an error or return null the try will be repeated. If the time out is reached a TimeoutRuntimeException will be thrown.- Parameters:
provider-timeout-nullAllowed-- Returns:
- The requested value
-
getAsynchronWithTimeout
public static <T> T getAsynchronWithTimeout(ValueProvider<T> provider, long timeout, boolean nullAllowed)
Like getWithTimeout but executed in a separate task, this means unblocking.- Parameters:
provider-timeout-nullAllowed-- Returns:
- The requested value
-
getAsynchronWithTimeout
public static <T> T getAsynchronWithTimeout(ValueProvider<T> provider, long timeout) throws Exception
Calls the provider once and will return the result. The provider is called in a separate thread to- Parameters:
provider-timeout-- Returns:
- The requested value
- Throws:
Exception
-
waitFor
public static void waitFor(Checker checker, long timeout)
Wait for the checker to return true or throw an TimeoutRuntimeException on timeout. A exception in the checker will be ignored.- Parameters:
checker-timeout-
-
waitForWithException
public static void waitForWithException(Checker checker, long timeout) throws Exception
Wait for the checker to return true or throw an TimeoutRuntimeException on timeout.- Parameters:
checker-timeout-- Throws:
Exception- Thrown if checker throws an exception
-
getThread
public Thread getThread()
-
-