Package delight.nashornsandbox.internal
Class ThreadMonitor
java.lang.Object
delight.nashornsandbox.internal.ThreadMonitor
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
FieldsModifier and TypeFieldDescriptionprivate final AtomicBooleanprivate final longprivate final longprivate final com.sun.management.ThreadMXBeanprivate final AtomicIntegerprivate static final intprivate final Objectprivate final AtomicBooleanCheck if interrupted script has finished.private final AtomicBooleanCheck if script should be killed to stop it when abusive.private final intprivate final AtomicBooleanprivate ThreadMXBeanprivate Threadprivate boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate longgetCheckInterval(long runtime) private longprivate longObtain current evaluation thread memory usage.booleanprivate booleanisCpuTimeExided(long runtime) booleanbooleanprivate booleanisStageMemoryExided(long memory) booleanprivate voidreset()voidrun()voidvoid
-
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
-
scriptFinished
Check if interrupted script has finished. -
scriptKilled
Check if script should be killed to stop it when abusive. -
cpuLimitExceeded
-
memoryLimitExceededStage
-
monitor
-
threadToMonitor
-
timedOutWaitingForThreadToMonitor
private boolean timedOutWaitingForThreadToMonitor -
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
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
-
scriptFinished
public void scriptFinished() -
isCPULimitExceeded
public boolean isCPULimitExceeded() -
isMemoryLimitExceeded
public boolean isMemoryLimitExceeded() -
isScriptKilled
public boolean isScriptKilled()
-