Package delight.nashornsandbox.internal
Class ThreadMonitor
- java.lang.Object
-
- delight.nashornsandbox.internal.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 Summary
Fields Modifier and Type Field Description private java.util.concurrent.atomic.AtomicBoolean
cpuLimitExceeded
private long
maxCPUTime
private long
maxMemory
private com.sun.management.ThreadMXBean
memoryCounter
private java.util.concurrent.atomic.AtomicInteger
memoryLimitExceededStage
private static int
MILI_TO_NANO
private java.lang.Object
monitor
private java.util.concurrent.atomic.AtomicBoolean
scriptFinished
Check if interrupted script has finished.private java.util.concurrent.atomic.AtomicBoolean
scriptKilled
Check if script should be killed to stop it when abusive.private int
stageOffset
private java.util.concurrent.atomic.AtomicBoolean
stop
private java.lang.management.ThreadMXBean
threadBean
private java.lang.Thread
threadToMonitor
private boolean
timedOutWaitingForThreadToMonitor
-
Constructor Summary
Constructors Constructor Description ThreadMonitor(long maxCPUTime, long maxMemory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private long
getCheckInterval(long runtime)
private long
getCPUTime()
private long
getCurrentMemory()
Obtain current evaluation thread memory usage.boolean
isCPULimitExceeded()
private boolean
isCpuTimeExided(long runtime)
boolean
isMemoryLimitExceeded()
boolean
isScriptKilled()
private boolean
isStageMemoryExided(long memory)
boolean
registerThreadToMonitor(java.lang.Thread t)
private void
reset()
void
run()
void
scriptFinished()
void
stopMonitor()
-
-
-
Field Detail
-
MILI_TO_NANO
private static final int MILI_TO_NANO
- See Also:
- Constant Field Values
-
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
-
-
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()
-
-