📄 threaddemo3.java
字号:
// 例4.1.3 ThreadDemo3.java
class NewThread implements Runnable // 实现了Runnable接口
{
public void run() // 覆写Runnable 接口中唯一的run()方法,这是线程的入口
{
for( int i=10 ; i>0 ;i--)
{
try
{
System.out.println("left time: "+ i);
Thread.sleep(1000); //当前线程睡眠1000毫秒
}catch(InterruptedException e){ //处理异常
System.out.println(e.getMessage());
}
}
System.out.println("game is over,bye!");
}
}
class ThreadDemo3
{
public static void main(String args[])
{
NewThread newthread = new NewThread();
Thread thd = new Thread(newthread, "Thread Demo")
thd.start(); //启动线程,调用run()方法
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -