📄 twothreadsdemo2.java
字号:
public class TwoThreadsDemo2 implements Runnable{
Thread mythread1,mythread2,myth;
public void run() {
myth= Thread.currentThread();
for (int i = 0; i < 10; i++) {
System.out.println(i +myth.getName());
try {
Thread.sleep((long)(Math.random() * 1000));
} catch (InterruptedException e) {}
}
System.out.println("DONE! " );
}
public void test(){
mythread1= new Thread(this,"a");
mythread2= new Thread(this ,"b");
mythread1.start();
mythread2.start();
}
public static void main (String[] args) {
new TwoThreadsDemo2().test();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -