Package delight.nashornsandbox.internal
Class ThreadMonitor
- java.lang.Object
-
- delight.nashornsandbox.internal.ThreadMonitor
-
public class ThreadMonitor extends java.lang.ObjectJS 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.AtomicBooleancpuLimitExceededprivate longmaxCPUTimeprivate longmaxMemoryprivate com.sun.management.ThreadMXBeanmemoryCounterprivate java.util.concurrent.atomic.AtomicIntegermemoryLimitExceededStageprivate static intMILI_TO_NANOprivate java.lang.Objectmonitorprivate java.util.concurrent.atomic.AtomicBooleanscriptFinishedCheck if interrupted script has finished.private java.util.concurrent.atomic.AtomicBooleanscriptKilledCheck if script should be killed to stop it when abusive.private intstageOffsetprivate java.util.concurrent.atomic.AtomicBooleanstopprivate java.lang.management.ThreadMXBeanthreadBeanprivate java.lang.ThreadthreadToMonitorprivate booleantimedOutWaitingForThreadToMonitor
-
Constructor Summary
Constructors Constructor Description ThreadMonitor(long maxCPUTime, long maxMemory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private longgetCheckInterval(long runtime)private longgetCPUTime()private longgetCurrentMemory()Obtain current evaluation thread memory usage.booleanisCPULimitExceeded()private booleanisCpuTimeExided(long runtime)booleanisMemoryLimitExceeded()booleanisScriptKilled()private booleanisStageMemoryExided(long memory)booleanregisterThreadToMonitor(java.lang.Thread t)private voidreset()voidrun()voidscriptFinished()voidstopMonitor()
-
-
-
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.InterruptedExceptionObtain 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()
-
-