⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 e1503.java

📁 java小程序
💻 JAVA
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -