Import java.net.url; import java.net.urlclassloader; import java.io.bufferedReader; import java.io.inputstreamReader; public class client {static classloader cl; static serveritf server;
Public static void loadNewVersionOfServer () throws exception {url serverURLS [] = new url [] {new url ("file: server /")}; // New version file placement location CL = new urlclassloader (serverURLS); // creation class Loader Server = (Serveritf) Cl.LoadClass ("ServerImpl"). NewInstance (); // Load the formula and generate instances}
public static void test () throws Exception {BufferedReader br = new BufferedReader (new InputStreamReader (System.in)); loadNewVersionOfServer (); while (true) {System.out.println ( "Enter QUOTE, RELOAD, GC, or QUIT: "); String cmdread = br.readline (); string cmd = cmdread.touppercase (); if (cmd.equals (" quit ")) // exits the program {return;} else if (cmd.equals ))) // {system.out.println (server.GetQuote ());} else if (cmd.equals ("reload")) // Load new class {loadNewVersionOfServer (); system.gc (); // Requires virtual machine recycling old-type loader system.RunFinalization ();} else if (cmd.equals ("gc")) {system.gc (); system.RunFinalization ();}}}
Public static void main (string args [);} catch (exception e) {E.PrintStackTrace ();}}}; public interface server server}};}; ; Reporter (Class CLS) {this.cls = cls; system.out.println ("ServerImpl class" cls.hashcode () "loaded INTO VM");}