• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Comparison between classloaders?

 
Ranch Hand
Posts: 1170
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Hey, check out my mega multi devastator cannon. It's wicked. It makes this tiny ad look weak:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic