Java Mailing List Archive

http://www.gg3721.com/

Home » user.groovy »

[groovy-user] Problems while creating large amount of Classes/Scripts at runtime

Lukasz Zmudzinski

2008-08-12

Replies: Find Java Web Hosting

Author LoginPost Reply
Hi,
  I would like to create large number of Classes/Scripts ( 20000+ would
be great ) at runtime. Tests underneath fail with an OutOfMemoryError,
allocating more memory not seems to help. Where is the bottleneck ?
What are the solutions for having running
20000 scripts? Should I precompile classes using Groovy Compiler and then
load them with the default ClassLoader? I'm using Groovy 1.5.6.

@Test
public void testGroovyClassLoaderPerformance(){
  final Integer times = 20000;
  List<Class> classes = new ArrayList<Class>(times);
  GroovyClassLoader gcl = new GroovyClassLoader();
  for (int i = 0; i < times; i++) {
   String scriptText = "object"+i+".foo()";
   Class<?> scriptClass = gcl.parseClass(scriptText);
   classes.add(scriptClass);
  }
}
@Test
public void testGroovyClassLoaderAndInvokerHelperPerformance(){
  final Integer times = 20000;
  List<Script> scripts = new ArrayList<Script>(times);
  GroovyClassLoader gcl = new GroovyClassLoader();
  for (int i = 0; i < times; i++) {
   String scriptText = "object"+i+".foo()";
   Class<?> scriptClass = gcl.parseClass(scriptText);
   Script script = InvokerHelper.createScript(scriptClass, new Binding());
   scripts.add(script);
  }
}

I've used BCEL to create even grater number of Classes at runtime, and it
was no problem for JVM.

Thanks for all the answers,

--
Lukasz Zmudzinski
Cracow University of Technology


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

  http://xircles.codehaus.org/manage_email


©2008 gg3721.com - Jax Systems, LLC, U.S.A.