Java Thread Test2
// Ttest2.java
// it contains a test java program, that defines a class jtest with
// a main function that prints howdy, and creates threads from the
// class Thread2.java
// It passes parameters to the threads, a name and an ID number.
// compile this file with the command "javac Ttest2.java"
// your path must include the bin directory of the jdk
// run the program with "java Ttest2"
// on some systems
class Ttest2 {
public static void main(String argv[]) {
System.out.println("Howdy from Ttest2");
new Thread2("Thread1", 0); //creates a thread
new Thread2("Thread2", 1); //creates another thread
}
}
//************* second file *************
// Thread2.java
// It is a thread class to be run from Ttest2
// It receives parameters from the parent, a thread name and ID number
// compile this file with the command "javac Thread2.java"
// your path must include the bin directory of the jdk
public class Thread2 extends Thread {
private int myid; // private to this thread
Thread2(String name, int me) { //constructor - executed when thread is created with new
super(name); //super is part of the Thread class
myid=me;
start(); // by default calls method "run"
}
public void run() {
System.out.println("Howdy from " + Thread.currentThread().getName() +
", id=" + myid);
}
}