Class ThreadMonitor


  • public class ThreadMonitor
    extends java.lang.Object
    JS executor thread monitor. It is designed to be run in main thread (the JS script is executed in other thread).

    Created on 2015-08-07

    Version:
    $Id$
    • Field Detail

      • maxCPUTime

        private final long maxCPUTime
      • maxMemory

        private final long maxMemory
      • stageOffset

        private final int stageOffset
      • stop

        private final java.util.concurrent.atomic.AtomicBoolean stop
      • scriptFinished

        private final java.util.concurrent.atomic.AtomicBoolean scriptFinished
        Check if interrupted script has finished.
      • scriptKilled

        private final java.util.concurrent.atomic.AtomicBoolean scriptKilled
        Check if script should be killed to stop it when abusive.
      • cpuLimitExceeded

        private final java.util.concurrent.atomic.AtomicBoolean cpuLimitExceeded
      • memoryLimitExceededStage

        private final java.util.concurrent.atomic.AtomicInteger memoryLimitExceededStage
      • monitor

        private final java.lang.Object monitor
      • threadToMonitor

        private java.lang.Thread threadToMonitor
      • timedOutWaitingForThreadToMonitor

        private boolean timedOutWaitingForThreadToMonitor
      • threadBean

        private java.lang.management.ThreadMXBean threadBean
      • memoryCounter

        private final com.sun.management.ThreadMXBean memoryCounter
    • Constructor Detail

      • ThreadMonitor

        public ThreadMonitor​(long maxCPUTime,
                             long maxMemory)
    • Method Detail

      • reset

        private void reset()
      • run

        public void run()
      • getCheckInterval

        private long getCheckInterval​(long runtime)
      • isCpuTimeExided

        private boolean isCpuTimeExided​(long runtime)
      • isStageMemoryExided

        private boolean isStageMemoryExided​(long memory)
      • getCurrentMemory

        private long getCurrentMemory()
                               throws java.lang.InterruptedException
        Obtain current evaluation thread memory usage. it must be empathises that the method 'getThreadAllocatedBytes' is not strictly accurate so mis killing might happen.
        Returns:
        current memory usage
        Throws:
        java.lang.InterruptedException
      • getCPUTime

        private long getCPUTime()
      • stopMonitor

        public void stopMonitor()
      • registerThreadToMonitor

        public boolean registerThreadToMonitor​(java.lang.Thread t)
      • scriptFinished

        public void scriptFinished()
      • isCPULimitExceeded

        public boolean isCPULimitExceeded()
      • isMemoryLimitExceeded

        public boolean isMemoryLimitExceeded()
      • isScriptKilled

        public boolean isScriptKilled()