• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Comparison between classloaders?

 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been trying to accomplish this for a while now, and there seems to be on easy way to accomplish it.

I have a class


Instances of this class may be loaded by seperate class loaders. The requirement is that no matter what classloader its loaded from, the instances are equal if the IDs are equal.

I have not found a good way to perform this comparison. The only way I have found so far is to serialize the instances into the same classloader, and perform the comparison there.

Alternately I could compare the class name. But classes could have the same name and be loaded from different library files. I suppose this is unavoidable since the only difference in this case IS the classloader possibly. I also found that its probably sensible to use some special technique to compare the SerialVersionID of the class too. Which I can do.

The bottom line is that I seem to be relegated to comparying class name, SerialVersionID, and the ID variable of the class. This is the only way without serializing the class.

Hmm, perhaps I could look at comparator interface?

Any tips?
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Surf over to www.javaworld.com and look for Java Tip 133. It will give you pointers for solving this problem.
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thats a novel idea, I didnt think about enums. I'm familiar with the techniques. However, they won't work here. The comparison already works when the class I have is in the same classloader. The problem is it fails when the classes are in seperate classloaders. So does their technique. Not only that, they bail calling it too much work and probably unnecessary

ahh well. ILl just have to serialize before I compare.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can't you load the class in a higher classloader so each section sees the same version of the loaded class? The other option is the 'Jini solution', where you can parse for and test the ID without deserialising the stream, but that's probably more effort than it's worth unless you do it a billion times a day.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic