Class ServiceThread

  • All Implemented Interfaces:
    java.lang.Runnable
    Direct Known Subclasses:
    NetService.NetIOThread, Service.StaticServiceThread

    public class ServiceThread
    extends java.lang.Thread
    This are the thread created by the factory in the class service, all the services run over this kind of thread.
    Author:
    javaito
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.lang.Thread

        java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
    • Field Summary

      • Fields inherited from class java.lang.Thread

        MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
    • 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 void checkAllocatedMemory()
      Verify if the current thread allocate more bytes that the max configured.
      static void checkExecutionTime()
      Verify if the current thread use more time that the max configured.
      static void checkInterruptedThread()
      Verify if the current thread is interrupted.
      static void configureMaxAllocatedMemory​(java.lang.Long maxAllocatedMemory)
      This method configure the max allocated memory for the current thread.
      static void configureMaxExecutionTime​(java.lang.Long maxExecutionTime)
      This method configure the max time of execution for the current thread.
      java.lang.Long getAccumulatedAllocatedMemory()  
      java.lang.Long getAccumulatedTime()
      Returns the accumulated time into the current thread.
      java.lang.Long getInitialAllocatedMemory()
      Returns the initial thread allocated memory counter when the current service session starts.
      java.lang.Long getInitialTime()
      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.Long getMaxAllocatedMemory()
      Returns the max allocated memory value for thread.
      java.lang.Long getMaxExecutionTime()
      Returns the max execution time value for thread.
      java.lang.Class<? extends Service> getServiceClass()
      Returns the class of the service that creates this thread.
      ServiceSession getSession()
      Return the session of the thread.
      void putLayer​(ServiceSession.LayerStackElement element)
      Add an element into the layer stack.
      void removeLayer()
      Remove the head of the layer stack.
      void setSession​(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
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • 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.InterruptedException
        Verify 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.Throwable
        Verify 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.Throwable
        Verify if the current thread use more time that the max configured.
        Throws:
        java.lang.Throwable - Throws a run time exception.