Package org.hcjf.service
Class ServiceThread
- java.lang.Object
-
- java.lang.Thread
-
- org.hcjf.service.ServiceThread
-
- All Implemented Interfaces:
java.lang.Runnable
- Direct Known Subclasses:
NetService.NetIOThread,Service.StaticServiceThread
public class ServiceThread extends java.lang.ThreadThis are the thread created by the factory in the class service, all the services run over this kind of thread.- Author:
- javaito
-
-
Constructor Summary
Constructors Constructor Description ServiceThread(java.lang.Runnable target, java.lang.String name)ServiceThread(Service service, java.lang.Runnable target, java.lang.String name)
-
Method Summary
Modifier and Type Method Description static voidcheckAllocatedMemory()Verify if the current thread allocate more bytes that the max configured.static voidcheckExecutionTime()Verify if the current thread use more time that the max configured.static voidcheckInterruptedThread()Verify if the current thread is interrupted.static voidconfigureMaxAllocatedMemory(java.lang.Long maxAllocatedMemory)This method configure the max allocated memory for the current thread.static voidconfigureMaxExecutionTime(java.lang.Long maxExecutionTime)This method configure the max time of execution for the current thread.java.lang.LonggetAccumulatedAllocatedMemory()java.lang.LonggetAccumulatedTime()Returns the accumulated time into the current thread.java.lang.LonggetInitialAllocatedMemory()Returns the initial thread allocated memory counter when the current service session starts.java.lang.LonggetInitialTime()Returns the initial thread time counter when the current service session starts.java.util.Collection<ServiceSession.LayerStackElement>getLayerStack()This method return the stack of layer of the session.java.lang.LonggetMaxAllocatedMemory()Returns the max allocated memory value for thread.java.lang.LonggetMaxExecutionTime()Returns the max execution time value for thread.java.lang.Class<? extends Service>getServiceClass()Returns the class of the service that creates this thread.ServiceSessiongetSession()Return the session of the thread.voidputLayer(ServiceSession.LayerStackElement element)Add an element into the layer stack.voidremoveLayer()Remove the head of the layer stack.voidsetSession(ServiceSession session)Set the session for the thread.-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, run, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
-
-
-
Constructor Detail
-
ServiceThread
public ServiceThread(Service service, java.lang.Runnable target, java.lang.String name)
-
ServiceThread
public ServiceThread(java.lang.Runnable target, java.lang.String name)
-
-
Method Detail
-
getServiceClass
public final java.lang.Class<? extends Service> getServiceClass()
Returns the class of the service that creates this thread.- Returns:
- Class of service.
-
putLayer
public final void putLayer(ServiceSession.LayerStackElement element)
Add an element into the layer stack.- Parameters:
element- Layer stack element.
-
removeLayer
public final void removeLayer()
Remove the head of the layer stack.
-
getLayerStack
public java.util.Collection<ServiceSession.LayerStackElement> getLayerStack()
This method return the stack of layer of the session.- Returns:
- Layer stack.
-
getSession
public final ServiceSession getSession()
Return the session of the thread.- Returns:
- Session of the thread.
-
getMaxAllocatedMemory
public final java.lang.Long getMaxAllocatedMemory()
Returns the max allocated memory value for thread.- Returns:
- Max allocated memory value.
-
getMaxExecutionTime
public final java.lang.Long getMaxExecutionTime()
Returns the max execution time value for thread.- Returns:
- Max execution time value.
-
getInitialAllocatedMemory
public java.lang.Long getInitialAllocatedMemory()
Returns the initial thread allocated memory counter when the current service session starts.- Returns:
- Initial thread allocated memory.
-
getAccumulatedAllocatedMemory
public final java.lang.Long getAccumulatedAllocatedMemory()
-
getInitialTime
public final java.lang.Long getInitialTime()
Returns the initial thread time counter when the current service session starts.- Returns:
- Initial thread time counter.
-
getAccumulatedTime
public final java.lang.Long getAccumulatedTime()
Returns the accumulated time into the current thread.- Returns:
- Accumulated time.
-
setSession
public final void setSession(ServiceSession session)
Set the session for the thread.- Parameters:
session- Service session.
-
configureMaxAllocatedMemory
public static void configureMaxAllocatedMemory(java.lang.Long maxAllocatedMemory)
This method configure the max allocated memory for the current thread. This configuration will be reset when the thread finalize with the current service session. If in the system properties the 'expressed in percentage flag' is true then this values will be considered as a percentage in the otherwise this value will be considered as a amount of bytes.- Parameters:
maxAllocatedMemory- Max allocated memory value.
-
configureMaxExecutionTime
public static void configureMaxExecutionTime(java.lang.Long maxExecutionTime)
This method configure the max time of execution for the current thread. This value are expressed in milliseconds.- Parameters:
maxExecutionTime- Max execution time value.
-
checkInterruptedThread
public static void checkInterruptedThread() throws java.lang.InterruptedExceptionVerify if the current thread is interrupted.- Throws:
java.lang.InterruptedException- Throws this exception if the current thread is interrupted.
-
checkAllocatedMemory
public static void checkAllocatedMemory() throws java.lang.ThrowableVerify if the current thread allocate more bytes that the max configured.- Throws:
java.lang.Throwable- Throws a run time exception.
-
checkExecutionTime
public static void checkExecutionTime() throws java.lang.ThrowableVerify if the current thread use more time that the max configured.- Throws:
java.lang.Throwable- Throws a run time exception.
-
-