// Concurrent Programming - CS 498-598
// Summer 2002 - A simple, threads-only program.
// Redefining Thread.run() eliminates the need to define a Runnable. This is
// usually of questionable value.
class
FriendlyThread
extends Thread {
public void
run() {
System.out.println("Hello world!");
}
}
class
HiThread {
public static void
main(String[] args) {
big();
little();
}
// The over-wrought, Java way to code up a thread. This code also tries to
// start a thread twice, which should cause an error the second time around.
private static void
big() {
FriendlyThread friendlyThread = new FriendlyThread();
friendlyThread.start();
try { friendlyThread.start(); }
catch (IllegalThreadStateException e) {
System.out.println("Caught an illegal thread state exception.");
}
}
// A somewhat more to the point version of the previous function, sans the
// double start.
private static void
little() {
(new FriendlyThread()).start();
}
}
syntax highlighted by Code2HTML, v. 0.9