• 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

"Un" registering classes

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm currently writing the Unit test for a class which instances are accessible only via a factory.
The Factory uses an array to return only one -specific- instances of the class. This is a sort of Singelton
Of course the factory is a static get<Method>.
The method uses a Collection to store existing reference & is, up to now, appropriatelly synchronized to avoid returning double instances even when accessed by multiple threads.
My question is (finally):
To make sure the system behaves OK, I'd like to be able to deregister the class. Something doing the opposite of
<code>
Class.forName("MyClassName");
</code>

This would allow me to run the test multiple times w/o having to ensure the class is always called with different parameters from one test to another.
Tx,
Thomas,

------------------
 
author
Posts: 621
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"tsmets",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please log in with a new name which meets the requirements.
Thanks.
Sean
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think a class is removed from the JVM only when the classloader which loaded it in the first place has been GC-ed.
I may be wrong. In that case to do the opposite of class.forName(), you might have to write your own classloader to load the classes and make the loader's reference point to null when you want to un-register the classes loaded by it.
You classloader needs to specify it's parent as null.
if the class to be loaded is A and if it is the classpath then
the parent will end up loading it which you don't want.
So if the parent is null then your loader will get a chance to load it.
just a suggestion i may be wrong. others can probably correct me
prav

Originally posted by tsmets:
I'm currently writing the Unit test for a class which instances are accessible only via a factory.
The Factory uses an array to return only one -specific- instances of the class. This is a sort of Singelton
Of course the factory is a static get<Method>.
The method uses a Collection to store existing reference & is, up to now, appropriatelly synchronized to avoid returning double instances even when accessed by multiple threads.
My question is (finally):
To make sure the system behaves OK, I'd like to be able to deregister the class. Something doing the opposite of
<code>
Class.forName("MyClassName");
</code>

This would allow me to run the test multiple times w/o having to ensure the class is always called with different parameters from one test to another.
Tx,
Thomas,


 
reply
    Bookmark Topic Watch Topic
  • New Topic