Java应用程序执行预编译的Groovy脚本需要很长时间

Java应用程序执行预编译的Groovy脚本需要很长时间,groovy,Groovy,我在服务器启动时预先编译了groovy脚本(我将groovy脚本存储为数据库中的varchar),如下所示: final Binding sharedData = new Binding(); final GroovyShell shell = new GroovyShell(sharedData); script= shell.parse(rs.getString("VALIDATION_SCRIPT")); 现在,当根据指定的验证id检查输入记录的验证时,我尝试执行预编译脚本,如下所示 S

我在服务器启动时预先编译了groovy脚本(我将groovy脚本存储为数据库中的varchar),如下所示:

final Binding sharedData = new Binding();
final GroovyShell shell = new GroovyShell(sharedData);
script= shell.parse(rs.getString("VALIDATION_SCRIPT"));
现在,当根据指定的验证id检查输入记录的验证时,我尝试执行预编译脚本,如下所示

Script scrpt = Validation.getScript(); //getting from cache
scrpt.getBinding().setVariable("attributes", objects);
scrpt.getBinding().setVariable("tools", scrpt);
GroovyResponse gr = scrpt.evaluate("tools.valid(attributes)");
但在这里,我的应用程序需要很长时间来评估。我猜堆大小也会增加,并且会发生GC。如果有更好的方法,谁能帮我。不影响性能

我的一个groovy脚本:

import com.fis.derivatives.utility.generic.model.GroovyResponse;

def valid(Map mapInput){
    GroovyResponse obj = new GroovyResponse()
    if(mapInput.inputVal.equals("1")){
        obj.setStatus(true) ;
        obj.setResultValue("B") ;
    } else if(mapInput.inputVal.equals("2")){
        obj.setStatus(true) ;
        obj.setResultValue("S") ;
    }else{
        obj.setStatus(false);
        obj.setComment("Error : Unable to extract BUY_SELL. Please check BS value "+mapInput.inputVal+".")
    }
    return obj;
}

1-我对你的缓存有疑问。从缓存中获取没有任何密钥是很奇怪的

Script scrpt = Validation.getScript(); //getting from cache
2-稍微修改一下groovy的要求:

Script scrpt = Validation.getScript(); //getting from cache
//we will pass attributes as a parameter to method
//scrpt.getBinding().setVariable("attributes", objects); 
//not necessary to pass to script link to itself 
//scrpt.getBinding().setVariable("tools", scrpt);

GroovyResponse gr = scrpt.invokeMethod​("valid", objects);

也许是剧本的问题?你能分享一下吗?下面这行代码也很奇怪:
scrpt.getBinding().setVariable(“tools”,scrpt)正在向脚本传递对此脚本的引用。。。这里可能有堆栈溢出;GroovyShell外壳=新的GroovyShell(绑定);binding.setVariable(“属性”,对象);binding.setVariable(“工具”,scrpt);evaluate(“tools.valid(attributes)”);groovy文件位于另一个commentimport com.fis.derivatives.utility.generic.model.GroovyResponse中;def valid(Map mapInput){GroovyResponse obj=new GroovyResponse()如果(mapInput.inputVal.equals(“1”){obj.setStatus(true);obj.setResultValue(B”)}如果(mapInput.inputVal.equals(“2”){obj.setStatus(true);obj.setResultValue(“S”)}其他{obj.setStatus(false);obj.setComment(“错误:无法提取买卖。请检查BS值”)+mapInput.inputVal+“)}返回obj;}请将此输入到您的问题中。完成。请帮助:(