JSR223 Sampler have a statement that Groovy is implementing Compilable interface
different than other scripting languages and therefore is recommended
To benefit from caching and compilation, the language engine used for
scripting must implement JSR223 Compilable interface (Groovy is one of
these, java, beanshell and javascript are not)
I tried to check it using similar code in JSR223 Sampler.
I tried to check all available languages with Compilable:
import javax.script.Compilable;
import javax.script.ScriptEngineFactory;
import javax.script.ScriptEngineManager;
ScriptEngineManager mgr = new ScriptEngineManager();
engineFactories = mgr.getEngineFactories();
for (ScriptEngineFactory engineFactory : engineFactories) {
if (engineFactory instanceof Compilable) {
log.info(engineFactory.getEngineName() + " Script compilation is supported.");
} else {
log.info(engineFactory.getEngineName() + " Script compilation is not supported.");
}
}
My result is:
Oracle Nashorn Script compilation is not supported.
JEXL Engine Script compilation is not supported.
Groovy Scripting Engine Script compilation is not supported.
JEXL Engine Script compilation is not supported.
Velocity Script compilation is not supported.
BeanShell Engine Script compilation is not supported.
Meaning none support compilation,
EDIT 1
I change according to @aristotll the check and now it returns that all support compilation
final ScriptEngine engine = engineFactory.getScriptEngine();
if (engine instanceof Compilable) {
EDIT 2
I change according to @aristotll second edit
try {
((Compilable) engine).compile("");
log.info(engineFactory.getEngineName() + " Script compilation is supported.");
} catch (Error e) {
log.info(engineFactory.getEngineName() + " Script compilation is not supported.");
I'm getting interesting result: Nashorn and JEXL support it
Groovy Scripting Engine Script compilation is supported.
Oracle Nashorn Script compilation is supported.
JEXL Engine Script compilation is supported.
BeanShell Engine Script compilation is not supported.
JEXL Engine Script compilation is supported.
Am I checking something wrong? Do I need to import more jars to enable it?
How can I know if scripting engine uses caching and compilation? is JMeter's statement is wrong/outdated ?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…