1616import java .lang .reflect .Method ;
1717import java .util .List ;
1818import java .util .Map ;
19+ import java .util .concurrent .TimeUnit ;
1920import java .util .regex .Matcher ;
2021import java .util .regex .Pattern ;
2122
@@ -38,11 +39,17 @@ public class CodeEvaluator {
3839 }
3940
4041 private final String name ;
42+ private final long timeoutDuration ;
43+ private final TimeUnit timeoutUnit ;
44+ private final JJavaLoaderDelegate loaderDelegate ;
4145 private final JJavaExecutionControl execControl ;
4246
43- public CodeEvaluator (String name , JJavaExecutionControl execControl ) {
47+ public CodeEvaluator (String name , long timeoutDuration , TimeUnit timeoutUnit ) {
4448 this .name = name ;
45- this .execControl = execControl ;
49+ this .timeoutDuration = timeoutDuration ;
50+ this .timeoutUnit = timeoutUnit ;
51+ this .loaderDelegate = new JJavaLoaderDelegate ();
52+ this .execControl = new JJavaExecutionControl (loaderDelegate , timeoutDuration , timeoutUnit );
4653 }
4754
4855 public ExecutionControlProvider getExecControlProvider () {
@@ -120,7 +127,7 @@ protected Object evalSingle(JShell shell, String code, EvalTimer timer) {
120127 EvalException ee = (EvalException ) e ;
121128 switch (ee .getExceptionClassName ()) {
122129 case JJavaExecutionControl .EXECUTION_TIMEOUT_NAME :
123- throw new EvaluationTimeoutException (execControl . getTimeoutDuration (), execControl . getTimeoutUnit () , code .trim ());
130+ throw new EvaluationTimeoutException (timeoutDuration , timeoutUnit , code .trim ());
124131 case JJavaExecutionControl .EXECUTION_INTERRUPTED_NAME :
125132 throw new EvaluationInterruptedException (code .trim ());
126133 default :
@@ -239,7 +246,7 @@ public void interrupt() {
239246 }
240247
241248 public ClassLoader getClassLoader () {
242- return execControl .getClassLoader ();
249+ return loaderDelegate .getClassLoader ();
243250 }
244251
245252 static final class SimpleExecControlProvider implements ExecutionControlProvider {
0 commit comments