📄 c_6.java
字号:
public class c_6{
public static void main(String args[])
{
//创建线程以MyRunable的对象为目标对象
Thread thread1=new Thread(new MyRunable(300),"线程1");
Thread thread2=new Thread(new MyRunable(500),"线程2");
Thread thread3=new Thread(new MyRunable(700),"线程3");
thread1.start();
thread2.start();
thread3.start();
//判断线程是否结束
if(thread1.isAlive())
System.out.println("线程1结束");
if(thread2.isAlive())
System.out.println("线程2结束");
if(thread3.isAlive())
System.out.println("线程3结束");
}
}
class MyRunable implements Runnable{
private int sleepTime;
private String s;
public MyRunable(int time)
{
sleepTime=time;
}
public void run()
{
try
{for(int i=1;i<=3;i++)
{
Thread.sleep(sleepTime);
s=Thread.currentThread().getName();
System.out.println("线程:"+s);
}
}catch(InterruptedException e){}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -