diff options
-rw-r--r-- | build.xml | 27 | ||||
-rw-r--r-- | sample/evolve/DemoServer.java | 3 | ||||
-rw-r--r-- | sample/evolve/WebPage.class.0 | bin | 686 -> 0 bytes | |||
-rw-r--r-- | sample/evolve/WebPage.class.1 | bin | 812 -> 0 bytes | |||
-rw-r--r-- | sample/evolve/WebPage.java | 14 | ||||
-rw-r--r-- | sample/evolve/demo.html | 3 | ||||
-rw-r--r-- | sample/evolve/sample/evolve/WebPage.java | 20 | ||||
-rw-r--r-- | sample/evolve/start.html | 14 | ||||
-rw-r--r-- | tutorial/tutorial.html | 21 |
9 files changed, 72 insertions, 30 deletions
@@ -52,9 +52,29 @@ deprecation="on" optimize="off" includes="sample/**" - excludes="sample/hotswap/**"> + excludes="sample/hotswap/**,sample/evolve/sample/**"> <classpath refid="classpath"/> </javac> + + <copy file="sample/vector/Test.j" + todir="${build.classes.dir}/sample/vector"/> + + <javac srcdir="${basedir}/sample/evolve" + destdir="${build.classes.dir}/sample/evolve/" + debug="on" + deprecation="on" + optimize="off" + includes="sample/**"> + <classpath refid="classpath"/> + </javac> + <copy todir="${build.classes.dir}/sample/evolve"> + <fileset dir="sample/evolve"/> + </copy> + <copy file="${build.classes.dir}/sample/evolve/WebPage.class" + tofile="${build.classes.dir}/sample/evolve/WebPage.class.0"/> + <copy file="${build.classes.dir}/sample/evolve/sample/evolve/WebPage.class" + tofile="${build.classes.dir}/sample/evolve/WebPage.class.1"/> + <javac srcdir="${basedir}/sample/hotswap" destdir="${build.classes.dir}" debug="on" @@ -72,11 +92,6 @@ includes="*"> <classpath refid="classpath"/> </javac> - <copy file="sample/vector/Test.j" - todir="${build.classes.dir}/sample/vector"/> - <copy todir="${build.classes.dir}/sample/evolve"> - <fileset dir="sample/evolve"/> - </copy> <echo>To run the sample programs without ant, change the current directory to ${build.classes.dir}.</echo> </target> diff --git a/sample/evolve/DemoServer.java b/sample/evolve/DemoServer.java index d69d055f..dd64c550 100644 --- a/sample/evolve/DemoServer.java +++ b/sample/evolve/DemoServer.java @@ -19,7 +19,8 @@ import java.io.*; * server overwrites WebPage.class (class file) and calls update()
* in VersionManager so that WebPage.class is loaded into the JVM
* again. The new contents of WebPage.class are copied from
- * either WebPage.class.0 or WebPage.class.1.
+ * either sample/evolve/WebPage.class
+ * or sample/evolve/sample/evolve/WebPage.class.
*/
public class DemoServer extends Webserver {
diff --git a/sample/evolve/WebPage.class.0 b/sample/evolve/WebPage.class.0 Binary files differdeleted file mode 100644 index 3cc1d743..00000000 --- a/sample/evolve/WebPage.class.0 +++ /dev/null diff --git a/sample/evolve/WebPage.class.1 b/sample/evolve/WebPage.class.1 Binary files differdeleted file mode 100644 index fe49380e..00000000 --- a/sample/evolve/WebPage.class.1 +++ /dev/null diff --git a/sample/evolve/WebPage.java b/sample/evolve/WebPage.java index 7c2b7cfb..7d420fef 100644 --- a/sample/evolve/WebPage.java +++ b/sample/evolve/WebPage.java @@ -8,7 +8,6 @@ import java.util.*; * show() on the created object.
*/
-// WebPage.class.0
public class WebPage {
public void show(OutputStreamWriter out) throws IOException {
Calendar c = new GregorianCalendar();
@@ -16,16 +15,3 @@ public class WebPage { out.write("<P><A HREF=\"demo.html\">Return to the home page.</A>");
}
}
-/*
-// WebPage.class.1
-public class WebPage {
- public void show(OutputStreamWriter out) throws IOException {
- out.write("<H2>Current Time:</H2>");
- Calendar c = new GregorianCalendar();
- out.write("<CENTER><H3><FONT color=\"blue\">");
- out.write(c.getTime().toString());
- out.write("</FONT></H3></CENTER><HR>");
- out.write("<P><A HREF=\"demo.html\">Return to the home page.</A>");
- }
-}
-*/
diff --git a/sample/evolve/demo.html b/sample/evolve/demo.html index 6be4a2c3..3eedf3da 100644 --- a/sample/evolve/demo.html +++ b/sample/evolve/demo.html @@ -31,7 +31,8 @@ again, you will see a different page on your browser. <P>Web server: <A HREF="DemoServer.java"><code>DemoServer.java</code></A>
-<P>WebPage: <A HREF="WebPage.java"><code>WebPage.java</code></A>
+<P>WebPage: <A HREF="WebPage.java"><code>WebPage.java</code></A> and
+another <A HREF="sample/evolve/WebPage.java"><code>WebPage.java</code></A>
<P>Class loader: <A HREF="DemoLoader.java"><code>DemoLoader.java</code></A>,
<A HREF="Evolution.java"><code>Evolution.java</code></A>, and
diff --git a/sample/evolve/sample/evolve/WebPage.java b/sample/evolve/sample/evolve/WebPage.java new file mode 100644 index 00000000..507b9564 --- /dev/null +++ b/sample/evolve/sample/evolve/WebPage.java @@ -0,0 +1,20 @@ +package sample.evolve;
+
+import java.io.*;
+import java.util.*;
+
+/**
+ * Updatable class. DemoServer instantiates this class and calls
+ * show() on the created object.
+ */
+
+public class WebPage {
+ public void show(OutputStreamWriter out) throws IOException {
+ out.write("<H2>Current Time:</H2>");
+ Calendar c = new GregorianCalendar();
+ out.write("<CENTER><H3><FONT color=\"blue\">");
+ out.write(c.getTime().toString());
+ out.write("</FONT></H3></CENTER><HR>");
+ out.write("<P><A HREF=\"demo.html\">Return to the home page.</A>");
+ }
+}
diff --git a/sample/evolve/start.html b/sample/evolve/start.html index d31d9d08..8ab3f940 100644 --- a/sample/evolve/start.html +++ b/sample/evolve/start.html @@ -1,14 +1,14 @@ <h2>Instructions</h2>
<p>1. Compile <code>sample/evolve/*.java</code>.
- Copy <code>WebPage.class</code> to <code>WebPage.class.0</code>.
-<p>2. Edit <code>Webpage.java</code>, compile it,
- and copy <code>WebPage.class</code> to <code>WebPage.class.1</code>.
-<br><code>WebPage.class.0</code> and
- <code>WebPage.class.1</code> are used
- for changing the contents of <code>WebPage.class</code> during
- the demo.
+<p>2. change the current directory to <code>sample/evolve</code><br>
+and compile there <code>sample/evolve/WebPage.java</code><br>
+(i.e. compile <code>sample/evolve/sample/evolve/WebPage.java</code>).
+
+<p>The two versions of <code>WebPage.class</code> are used<br>
+for changing the contents of <code>WebPage.class</code> during
+the demo.
<p>3. Run the server on the local host (where your web browser is running):
diff --git a/tutorial/tutorial.html b/tutorial/tutorial.html index 709d2148..4670424e 100644 --- a/tutorial/tutorial.html +++ b/tutorial/tutorial.html @@ -584,7 +584,8 @@ Once a class loader loads a class, it cannot reload a modified version of that class during runtime. Thus, you cannot alter the definition of a class after the JVM loads it. However, the JPDA (Java Platform Debugger Architecture) provides -limited ability for reloading a class. See "HotSwap" of JPDA for details. +limited ability for reloading a class. +See <a href="#hotswap">Section 3.6</a>. </ul> <p>If the same class file is loaded by two distinct class loaders, @@ -999,6 +1000,24 @@ binary code license.</i> <p><br> +<a name="hotswap"> +<h3>3.6 Reloading a class at runtime</h3></a> + +<p>If the JVM is launched with the JPDA (Java Platform Debugger +Architecture) enabled, a class is dynamically reloadable. After the +JVM loads a class, the old version of the class definition can be +unloaded and a new one can be reloaded again. That is, the definition +of that class can be dynamically modified during runtime. However, +the new class definition must be somewhat compatible to the old one. +<em>The JVM does not allow schema changes between the two versions.</em> +They have the same set of methods and fields. + +<p>Javassist provides a convenient class for reloading a class at runtime. +For more information, see the API documentation of +<code>javassist.tool.HotSwapper</code>. + +<p><br> + <a href="tutorial2.html">Next page</a> <hr> |