其实代码第一行是package ....,不过是在公司写的,所以删除了。
import java.util.Date;
public class RunnableTest implements Runnable {
private Date date = new Date();
private Thread timeThread = null;
public void start() {
timeThread = new Thread(this);
timeThread.start();
}
public void stop() {
timeThread = null;
}
@SuppressWarnings("static-access")
public void run() {
Thread currentThread = Thread.currentThread();
while (timeThread == currentThread) {
date = new Date();
System.out.println(date);
try {
timeThread.sleep(1000);
} catch (InterruptedException e) {
System.out.println(e.getMessage());
}
}
}
public static void main(String[] args) {
RunnableTest test = new RunnableTest();
test.start();
}
}