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 AtomicBoolean
private final long
private final long
private final com.sun.management.ThreadMXBean
private final AtomicInteger
private static final int
private final Object
private final AtomicBoolean
Check if interrupted script has finished.private final AtomicBoolean
Check if script should be killed to stop it when abusive.private final int
private final AtomicBoolean
private ThreadMXBean
private Thread
private boolean
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate long
getCheckInterval
(long runtime) private long
private long
Obtain current evaluation thread memory usage.boolean
private boolean
isCpuTimeExided
(long runtime) boolean
boolean
private boolean
isStageMemoryExided
(long memory) boolean
private void
reset()
void
run()
void
void
-
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()
-