Groovy update causing a ton of dead GroovyClassLoaders in PermGen

后端 未结 2 736
独厮守ぢ
独厮守ぢ 2021-01-15 17:29

I have a Java 7 project that runs scripts every n minutes by n processes. Here is an example of the code that runs the scripts.

ScheduledFuture scheduledFutu         


        
2条回答
  •  梦谈多话
    2021-01-15 18:22

    i had same problem when using groovy script for compiling and running. I finally work out with these way: 1. if you work with java version under 7 , you can use codes below to clean your class after compiled

     public static void clearAllClassInfo(Class type) throws Exception {
        Field globalClassValue = ClassInfo.class.getDeclaredField("globalClassValue");
        globalClassValue.setAccessible(true);
        GroovyClassValue classValueBean = (GroovyClassValue) globalClassValue.get(null);
        classValueBean.remove(type);
    }
    

    2. otherwise you are lucky, because you just need add an properties in SystemProperties

    -Dgroovy.use.classvalue=true
    

提交回复
热议问题