• Post Reply Bookmark Topic Watch Topic
  • New Topic

ClassLoader - lazy versus eager  RSS feed

 
Edward Fox
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there -

I have 100+ Google Protocol Buffer classes, which are all machine generated, and all identified by a unique constant inside the class definition. (Designed by others, criticized by me of course). I need to build a run-time id-to-class map. I can do this easily walking the classloader and using reflection to look for the constants.

It all works fine in Eclipse, which I suspect is using an eager classloader for the IDE code completion and debugging. When I run my code from the command-line, I get an empty map. So I think I'm facing a lazy loading classloader in the general case.

How difficult is it to make my own eager loading classloader? Any example code?

I know there are many build-time alternatives to manage this. But the class loader seems much more slick and ultimately easier to maintain.

Thanks!

 
Ramon Anger
Ranch Hand
Posts: 56
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Edward,

it depends on the JVM you use. In IBM's JVM you can use -Dibm.cl.eagerresolution to switch eager class loading on. The Sun (Oracle) JVM doesn't have that kind of switch. But you can check, which kind of class loading is used. See http://stackoverflow.com/questions/599602/eager-java-class-loading

Regards,
Ramon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!