Class ThreadMonitor

java.lang.Object
delight.nashornsandbox.internal.ThreadMonitor

public class ThreadMonitor extends 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 Details

    • MILI_TO_NANO

      private static final int MILI_TO_NANO
      See Also:
    • maxCPUTime

      private final long maxCPUTime
    • maxMemory

      private final long maxMemory
    • stageOffset

      private final int stageOffset
    • stop

      private final AtomicBoolean stop
    • scriptFinished

      private final AtomicBoolean scriptFinished
      Check if interrupted script has finished.
    • scriptKilled

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

      private final AtomicBoolean cpuLimitExceeded
    • memoryLimitExceededStage

      private final AtomicInteger memoryLimitExceededStage
    • monitor

      private final Object monitor
    • threadToMonitor

      private Thread threadToMonitor
    • timedOutWaitingForThreadToMonitor

      private boolean timedOutWaitingForThreadToMonitor
    • threadBean

      private ThreadMXBean threadBean
    • memoryCounter

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

    • ThreadMonitor

      public ThreadMonitor(long maxCPUTime, long maxMemory)
  • Method Details

    • 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 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:
      InterruptedException
    • getCPUTime

      private long getCPUTime()
    • stopMonitor

      public void stopMonitor()
    • registerThreadToMonitor

      public boolean registerThreadToMonitor(Thread t)
    • scriptFinished

      public void scriptFinished()
    • isCPULimitExceeded

      public boolean isCPULimitExceeded()
    • isMemoryLimitExceeded

      public boolean isMemoryLimitExceeded()
    • isScriptKilled

      public boolean isScriptKilled()