📄 e0373f495675001d187dee36bb048aa6
字号:
/*【例9-7】 设计一个程序,先创建一个线程,每隔1秒钟在命令行窗口输出本地机器的时间;
* 3秒钟后,该线程又被分配了实体。查看运行结果。
*/
//程序清单9-7: Example9_7.java
import java.util.Date;
public class Example9_7 {
public static void main(String args[]) {
TestThread7 test7 = new TestThread7();
Thread thread = new Thread(test7);
thread.start();
}
}
class TestThread7 implements Runnable {
int time = 0;
public void run() {
while (true) {
System.out.println(new Date());
time++;
try {
Thread.sleep(800);
} catch (InterruptedException e) {
}
if (time == 3) {
Thread thread = Thread.currentThread();
thread = new Thread(this);
thread.start();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -