testthread1.java
来自「这是一张java应用教程的随书光盘」· Java 代码 · 共 31 行
JAVA
31 行
class TestThread
{ static AThread aThread;static BThread bThread;
public static void main(String args[])
{ aThread=new AThread() ;//创建两个线程。
bThread=new BThread();
aThread.start(); //线程开始运行后,Lefthand类中的run方法将被执行。
bThread.start();
}
}
class AThread extends Thread
{
public void run()
{
for(int i=0;i<=2;i++)
{ System.out.println("I am A"+i);
try{sleep(600);}
catch(InterruptedException e){}
}
}
}
class BThread extends Thread
{
public void run()
{
for(int i=0;i<=2;i++)
{System.out.println("I am B"+i);
try{sleep(400);}
catch(InterruptedException e){}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?