package com.smtscript.lib.threadpool; import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; import org.mozilla.javascript.NativeFunction; import com.smtscript.lib.JSStaticThreadPool; public class JSThreadPoolExecutor { protected JSStaticThreadPool _parent; protected ExecutorService _execSvr; public JSStaticThreadPool __parent__() { return _parent; } public JSThreadPoolExecutor(JSStaticThreadPool parent, ExecutorService execSvr) { _parent = parent; _execSvr = execSvr; } public void execute(NativeFunction func) { JSThreadPoolRunnable run = new JSThreadPoolRunnable(this, func); _execSvr.execute(run); } public void execute(int count, NativeFunction func) { for(int i = 0; i < count; i ++) { execute(func); } } public void shutdown() { _execSvr.shutdown(); } public boolean join(int time) throws Exception { if(time >= 0) return _execSvr.awaitTermination(time, TimeUnit.MICROSECONDS); else return _execSvr.awaitTermination(Integer.MAX_VALUE, TimeUnit.DAYS); } }