• 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

Class Unloading

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How to unload the classes in java?
 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Recreate your class loader?
 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A Classloader is garbage collected when none of the classes loaded by it is used anymore.And when the classloader is gone,your class is 'unloaded'.

So try creating another classloader and begin loading your classed with it,
derefer the classed loaded by the previous loader and you're done.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It gets a little spooky. This code is just typed ... not compiled or tested but I think the basic idea is sound:

Thing one (for cat in hat fans) will be loaded by the default class loader. Thing two will be loaded by a new class loader. If the file thing.class on disk changed since it was first referenced by the default class loader, they might have different versions of the class. That could lead to some very puzzling bugs!

It is done, tho. The JSP container recompiles and reloads JSPs if they have changed on disk. JUnit has an option to load the class under test every time it runs. Some debuggers can reload classes without stopping and restarting a program. But be careful!
 
reply
    Bookmark Topic Watch Topic
  • New Topic