I am using Apache Commons Pool to create a pool of Nashorn engines. On application start I call preparePool()
to warm up the minIdle
number of instances to eval()
all scripts into the engine so that it is ready to answer calls to invokeFunction()
immediately.
The warmup
@Override
public NashornScriptEngine create() {
// ...
try {
engine.eval(asset1);
engine.eval(asset2);
engine.eval(asset3);
} // ...
return engine;
}
Depending on the pool size and the complexity of the preloaded scripts this takes a considerable amount of time.
Questions
Can I warmup only one instance and safely clone it to the number of
minIdle
instances?Could a clone of a created instance be safely serialized and persisted? (which would allow maintaining an engine cache that only needed to be invalidated if one of the assets changes)
Related resources (will update this section when appropriate)