An efficient way to prepare the Apache Commons pool of our engines

I use the Apache Commons Pool to create a pool of Nashorn engines. When I launch the application, I call preparePool()to warm the number of instances minIdleto eval()all the scripts in the engine so that it is ready to immediately answer calls invokeFunction().

Warm up

@Override
public NashornScriptEngine create() {
    // ...
    try {
        engine.eval(asset1);
        engine.eval(asset2);
        engine.eval(asset3);
    } // ...
    return engine;
}

Depending on the size of the pool and the complexity of the pre-loaded scripts, this takes a considerable amount of time.

Questions

  • Can I heat up only one instance and safely clone it into the number of instances minIdle?

  • ? ( - , )

( )

+4
1

Nashorn . , ScriptEngine.createBindings() Bindings . , , Bindings ScriptEngine.eval(String|Reader, Bindings). ( ScriptContext, Bindings, out/err .)

ScriptEngine . script script ( Compilable), -.

+3

Source: https://habr.com/ru/post/1615728/


All Articles