The second way to create a thread is to use a class that implements java.lang.Runnable. Here is an example of such a class that has almost exactly the same functionality as MyThread class:
class MyRunnable implements Runnable {
private String parameter, name;
public MyRunnable(String name) {
this.name = name;
}
public void run() {
while(!"exit".equals(parameter)){
System.out.println("thread " + this.name +
", parameter: " + parameter);
pauseOneSecond();
}
System.out.println("thread " + this.name +
", parameter: " + parameter);
}
public void setParameter(String parameter) {
this.parameter = parameter;
}
}
The difference is that there is no isDaemon() method, getId...