I'm using a custom classloader to load some java classes. I need to execute some methods from these loaded classes in a loop. For each loop iteration I need a fresh initialization of all the classes (all static fields). I have measured that the execution time is three times slower if I use a new classloader for each iteration than the execution time when not using a fresh classloader in each iteration.
Can I reset the loaded classes to their initial state without loading them with a new classloader?
Or is there a way to speed up recurring loading of the same classes in different classloaders?