How do I RELOAD a class file?

I have a class called RecipeNode that I am creating an instance of when Apache-Tomcat starts (ie: When the machine boots). This class is wrapped in another class, RecipeService, that starts by creating a thread running RecipeNode;

class RecipeService

{

...

private static RecipeNode = null;

public static void create( String runDirectory)

{

...

node = new RecipeNode( runDirectory );

new Thread( node ).start();

...

}

}

When I make changes to the RecipeNode class, and then copy the new RecipeNode.class file to the server, I would like to end the RecipeNode thread, and start a new one using the code in the new class file.

I tried this using a reload() method in the RecipeService class. (The RecipeNode class has a shutdown method for this purpose, and runDirectory is static);

public static void reload()

{

if ( node != null )

{

node.shutdown();

}

node = new RecipeNode( runDirectory );

new Thread( node ).start();

}

A new thread is started properly when reload() is called (using a SOAP request), however, the new thread does not use the code in the new class file...

The only way I can reload the class at the moment is to restart Tomcat, and I want to avoid this unless I really have to.

Any ideas?

Thanks in anticipation!

[1421 byte] By [nemoent] at [2007-9-26 2:41:41]
# 1
The technique of hot-loading of classes, like what is done in servlet engines, involves the use of a non-default classloader. Here's a good article on one way of doing it: http://developer.java.sun.com/developer/TechTips/2000/tt1027.html#tip3Good luck!
DragonMan at 2007-6-29 10:17:41 > top of Java-index,Archived Forums,Java Programming...