runnabletest.java
来自「Java 2实用编程百例,一些比较实用的J2SE小程序,可以通过这些程序熟悉JA」· Java 代码 · 共 31 行
JAVA
31 行
package ch01.section10;
public class RunnableTest
implements Runnable {
//run()中while循环的次数
private int countDown = 5;
private static int threadCount = 0;
//记录线程数
private int threadNumber = ++threadCount;
//构造函数
public RunnableTest() {
//打印这是第几个线程
System.out.println("RunnableTest " + threadNumber);
}
public void run() {
while (true) {
//循环打印
System.out.println("Runnable " +
threadNumber + "(" + countDown + ")");
//每循环一次记数器减一
if (--countDown == 0) {
return;
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?