GroovyClassloader behaviour understanding ,
ScriptEngineManager factory = new ScriptEngineManager();
ScriptEngine engine = factory.getEngineByName("groovy");
GroovyScriptEngineImpl groovyEngineImpl = (GroovyScriptEngineImpl) engine;
in a loop,
for (int i = 0; i < 10; i++) {
long startTime = System.currentTimeMillis();
classLoader = new GroovyClassLoader(groovyEngineImpl.getClassLoader().getParent());
fileName = fileName + i;
Class groovyClass = classLoader.parseClass(s,fileName);
long endTime = System.currentTimeMillis();
System.out.println("Total elapsed time in execution o " + (endTime-startTime));
startTime = System.currentTimeMillis();
groovyClass = classLoader.parseClass(s,fileName);
endTime = System.currentTimeMillis();
System.out.println("Second Time Total elapsed time in execution o " + (endTime-startTime));
}
I have a couple of questions regarding the above code:
- In a for loop I'm creating a new groovyclassloder object, and parsing the groovy script twice. When the loop iterates for the second time, and tries to parse the groovyscript again, what will occur ?
- What will happen on the second time when another object is created. Will the classloader manage to get the class form the classpath or again recompile it again?
- When recompile is triggered, how does groovy know what the source is changed?