Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Classloading issue

 
Himanshu Gupta
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this fragment of code which always returns false.



Class Hierarchy..



The above a is an Object of SymRegIsland

Thanks in advance.


 
Ove Lindström
Ranch Hand
Posts: 326
Android Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


returns the Object that the JVM uses to find and load classes. That is of the type java.lang.ClassLoader. You are not extending that class.
 
Himanshu Gupta
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any way I can make it return the JobClassLoader...

 
Ove Lindström
Ranch Hand
Posts: 326
Android Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Himanshu Gupta wrote:Is there any way I can make it return the JobClassLoader...



Wait a minute now... you don't have to "return the JobClassLoader". Your class a IS A JobClassLoader.

Try:



Or are you doing something really cool with the JVM and ClassLoading?
 
Himanshu Gupta
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is some pre-written code and I am trying to make it run. I think I have to look deeper in this to get it resolved.
If I dont extend the Agent class by JobClassLoader is there any way I can make the following code return the JobClassLoader?


 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Himanshu Gupta wrote:This is some pre-written code and I am trying to make it run. I think I have to look deeper in this to get it resolved.
If I dont extend the Agent class by JobClassLoader is there any way I can make the following code return the JobClassLoader?




You forgot to post the "following" code.

As for looking deeper into it, I would definitely agree. To me a class hierarchy of what appears to be business objects descending from a ClassLoader is quite bizarre and quite possibly a candidate for the Daily WTF. But all I have seen is the class hierarchy so there may be a good reason for having done that. Or at least a reason...
 
Himanshu Gupta
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its a part of the software which runs genetic algorithms in a distributed Environment. The classes must be loaded using the URLClassLoader as the task is distributed among available peers.

And this is the code fragment I was talking about.

 
Himanshu Gupta
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator




This gives me output as



Is this correct. I expected it to be of JobClassLoader
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a's class needs to be loaded by your own class loader. That means that, first of all, its parent class loader should not load it. And that in turn means that the class to be loaded cannot be on the class path. After all, everything on the class path will already be found by the system class loader. A class loader will only be asked to load a class if its parent can't find it.
 
Himanshu Gupta
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:a's class needs to be loaded by your own class loader. That means that, first of all, its parent class loader should not load it. And that in turn means that the class to be loaded cannot be on the class path. After all, everything on the class path will already be found by the system class loader. A class loader will only be asked to load a class if its parent can't find it.


That was the real issue.
Thanks Rob.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic