eval is not thread safe. Added lock to avoid 'No such function invokeInternalXXX' exception (#4211)
* eval is not thread safe. Added lock to avoid 'No such function invokeInternalXXX' exception * License fix
This commit is contained in:
parent
6789cff802
commit
953054fadc
@ -40,6 +40,7 @@ import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
@Slf4j
|
||||
public abstract class AbstractNashornJsInvokeService extends AbstractJsInvokeService {
|
||||
@ -56,6 +57,8 @@ public abstract class AbstractNashornJsInvokeService extends AbstractJsInvokeSer
|
||||
private final FutureCallback<UUID> evalCallback = new JsStatCallback<>(jsEvalMsgs, jsTimeoutMsgs, jsFailedMsgs);
|
||||
private final FutureCallback<Object> invokeCallback = new JsStatCallback<>(jsInvokeMsgs, jsTimeoutMsgs, jsFailedMsgs);
|
||||
|
||||
private final ReentrantLock evalLock = new ReentrantLock();
|
||||
|
||||
@Getter
|
||||
private final JsExecutorService jsExecutor;
|
||||
|
||||
@ -121,10 +124,15 @@ public abstract class AbstractNashornJsInvokeService extends AbstractJsInvokeSer
|
||||
jsPushedMsgs.incrementAndGet();
|
||||
ListenableFuture<UUID> result = jsExecutor.executeAsync(() -> {
|
||||
try {
|
||||
if (useJsSandbox()) {
|
||||
sandbox.eval(jsScript);
|
||||
} else {
|
||||
engine.eval(jsScript);
|
||||
evalLock.lock();
|
||||
try {
|
||||
if (useJsSandbox()) {
|
||||
sandbox.eval(jsScript);
|
||||
} else {
|
||||
engine.eval(jsScript);
|
||||
}
|
||||
} finally {
|
||||
evalLock.unlock();
|
||||
}
|
||||
scriptIdToNameMap.put(scriptId, functionName);
|
||||
return scriptId;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user