Ray-Yan 2018-02-14 03:01 采纳率: 100%
浏览 2610
已结题

Groovy与java集成性能优化问题

Groovy与Java集成,class文件不断增加,导致perm区爆满。网上查了一些资料,但是不太理解,没有具体的解决代码示例,请帮忙写个demo参考一下。
如下代码:

这段代码中,cacheKey指什么,对应于脚本是怎么生成出来?等等

 private Map<String, Object> scriptCache = new ConcurrentHashMap<String, Object>();
...

Object scriptObject = null;
try {
    Binding binding = new Binding();
    binding.setVariable("context", this.context);
    binding.setVariable("clientInfo", clientInfo);
    binding.setVariable("params", params);
    binding.setVariable("data", data);

    Script shell = null;
    if (isCached(cacheKey)) {
        shell = (Script) getCaches().get(cacheKey);
    } else {
        shell = cache(cacheKey, script);
    }

    scriptObject = (Object) InvokerHelper.createScript(shell.getClass(), binding).run();

    // Cache
    if (!isCached(cacheKey)) {
        getCaches().put(cacheKey, shell);
    }
} catch (Throwable t) {
    log.error("groovy script eval error. script: " + script, t);
}

return scriptObject;

还有我在调用shell之前使用shell.getClassLoader().clearCache();之后,class依然是直线上升的,请问具体应该怎么用?
请各路大神写一个优化的demo参考一下,谢谢!

  • 写回答

1条回答 默认 最新

  • devmiao 2018-02-15 15:34
    关注
    评论

报告相同问题?