// Path: src/main/java/net/datenwerke/sandbox/exception/SandboxedTaskKilledException.java
// public class SandboxedTaskKilledException extends SandboxException {
// 
// 	/**
// 	 * 
// 	 */
// 	private static final long serialVersionUID = 3308981843831471410L;
// 
// 	public SandboxedTaskKilledException(String msg) {
// 		super(msg);
// 	}
// }


import java.util.logging.Logger;
import net.datenwerke.sandbox.exception.SandboxedTaskKilledException;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;
import java.util.Iterator;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
						continue;
					
					if(! monitor.isAlive()){
						iterator.remove();
						continue;
					}

					testStack(monitor);
					testRuntime(monitor);
				}
				
				try {
					Thread.sleep(checkInterval);
				} catch (InterruptedException e) {
					logger.log(Level.WARNING, "SandboxMonitor was interrupted", e);
				}
				
			} catch(Exception e){
				logger.log(Level.SEVERE, "Exception SandboxMonitorDaemon: ", e);
			}
		}
	}

	protected void testRuntime(SandboxMonitoredThread monitor) {
		SandboxContext context = monitor.getContext();
		if(0 > context.getMaximumRunTime() || null == context.getMaximumRunTimeUnit())
			return;
		if(context.getMaximumRuntimeMode() == SandboxContext.RuntimeMode.CPU_TIME){
			long cpuTime = threadBean.getThreadCpuTime(monitor.getMonitoredThread().getId());
			if(cpuTime > TimeUnit.NANOSECONDS.convert(context.getMaximumRunTime(), context.getMaximumRunTimeUnit()))
// Path: src/main/java/net/datenwerke/sandbox/exception/SandboxedTaskKilledException.java
// public class SandboxedTaskKilledException extends SandboxException {
// 
// 	/**
// 	 * 
// 	 */
// 	private static final long serialVersionUID = 3308981843831471410L;
// 
// 	public SandboxedTaskKilledException(String msg) {
// 		super(msg);
// 	}
// }


// Path: src/main/java/net/datenwerke/sandbox/SandboxMonitorDaemon.java
import java.util.logging.Logger;
import net.datenwerke.sandbox.exception.SandboxedTaskKilledException;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;
import java.util.Iterator;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;

						continue;
					
					if(! monitor.isAlive()){
						iterator.remove();
						continue;
					}

					testStack(monitor);
					testRuntime(monitor);
				}
				
				try {
					Thread.sleep(checkInterval);
				} catch (InterruptedException e) {
					logger.log(Level.WARNING, "SandboxMonitor was interrupted", e);
				}
				
			} catch(Exception e){
				logger.log(Level.SEVERE, "Exception SandboxMonitorDaemon: ", e);
			}
		}
	}

	protected void testRuntime(SandboxMonitoredThread monitor) {
		SandboxContext context = monitor.getContext();
		if(0 > context.getMaximumRunTime() || null == context.getMaximumRunTimeUnit())
			return;
		if(context.getMaximumRuntimeMode() == SandboxContext.RuntimeMode.CPU_TIME){
			long cpuTime = threadBean.getThreadCpuTime(monitor.getMonitoredThread().getId());
			if(cpuTime > TimeUnit.NANOSECONDS.convert(context.getMaximumRunTime(), context.getMaximumRunTimeUnit()))
				suspend(monitor, new SandboxedTaskKilledException("killed task as maxmimum runtime was exceeded"));