twothread.java
来自「介绍有关java的资料 课件 相当一本书籍 里面都是很基础的知识」· Java 代码 · 共 25 行
JAVA
25 行
class TwoThread implements Runnable {
TwoThread() {
Thread Thread1 = Thread.currentThread();
Thread1.setName("The first main thread");
System.out.println("The running thread:" + Thread1);
Thread Thread2 = new Thread(this,"the second thread");
System.out.println("creat another thread");
Thread2.start();
}
public void run() {
try {
for ( int i = 0; i < 5; i++ ) {
System.out.println("Sleep time for thread :"+i);
Thread.sleep(1000);
}
}
catch (InterruptedException e) {
System.out.println("thread has wrong");
}
}
public static void main(String args[]) {
new TwoThread();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?