JMeter Script Engine which allow caching and compilation

前端 未结 1 367
离开以前
离开以前 2020-12-20 06:49

JSR223 Sampler have a statement that Groovy is implementing Compilable interface different than other scripting languages and therefore is recommended

1条回答
  •  情话喂你
    2020-12-20 07:08

    You need to get ScriptEngine instance instead of ScriptEngineFactory

    final ScriptEngine engine = engineFactory.getScriptEngine();
    if (engine instanceof Compilable) {
    ...
    

    Why all Compilable? Because these script engines may be compilable in the future. But currently not support, so they all implement this interface. You may try to compile the empty string:

      if (engine instanceof Compilable) {
            try {
                ((Compilable) engine).compile("");
            } catch (Error e) {
                System.out.println(engineName + " Script compilation is not supported.");
            } catch (ScriptException e) {
                e.printStackTrace();
            }
            System.out.println(engineName + " Script compilation is supported.");
        } else {
            System.out.println(engineName + " Script compilation is not supported.");
        }
    

    0 讨论(0)
提交回复
热议问题