threaddemo.java
来自「使用Swing编写的记事本」· Java 代码 · 共 35 行
JAVA
35 行
class NewThread implements Runnable{
Thread t;
NewThread(){
t=new Thread(this,"Demo Thread");
System.out.println("Chile thread:"+t);
t.start();
}
public void run(){
try{
for(int i=5;i>0;i--){
System.out.println("Child Thread:"+i);
Thread.sleep(500);
}
}
catch(InterruptedException e){
System.out.println("Child interrupted.");
}
System.out.println("Exiting child thread.");
}
}
class ThreadDemo{
public static void main(String args[]){
new NewThread();
try{
for(int i=5;i>0;i--){
System.out.println("Main thread:"+i);
Thread.sleep(1000);
}
}
catch(InterruptedException e){
System.out.println("Main thread interrupted.");
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?