e1503.java
来自「java小程序」· Java 代码 · 共 40 行
JAVA
40 行
class PrintThread extends Thread
{
int sleepTime,count=0;
public PrintThread(int id)
{
super(String.valueOf(id));
sleepTime=(int)(Math.random()*1000);
System.out.println("Name="+super.getName()+" sleep="+sleepTime);
}
public void run()
{
while(true)
{
try
{
Thread.currentThread().sleep(sleepTime);
}
catch(InterruptedException e)
{System.out.println("Exception="+e.toString());}
System.out.print(getName()+" ");
if(++count>=10) break;
}
}
}
public class E1503
{
public static void main(String args[])
{
PrintThread thread1=new PrintThread(1);
PrintThread thread2=new PrintThread(2);
PrintThread thread3=new PrintThread(3);
PrintThread thread4=new PrintThread(4);
thread1.start();
thread2.start();
thread3.start();
thread4.start();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?