thread 改 Runable 的问题

来源:百度知道 编辑:UC知道 时间:2024/05/24 04:12:41
import java.util.Date;
public class exe8_1_1
{
static Athread threadA;
static Bthread threadB;
public static void main(String args[])
{
Thread threadA=new Thread(new Athread());
Thread threadB=new Thread(new Bthread());
threadA.start();
threadB.start();
}
}
class Athread implements Runnable
{
public void run()
{
for(int i=0;i<=3;i++)
{
Date timeNow = new Date();
System.out.println("A" + timeNow.toString());
try
{
sleep(2000);
}
catch(InterruptedException e)
{
}
}
}
}
class Bthread implements Runnable
{
public void run()
{
for(int i=0;i<=5;i++)
{
Date timeNow = new Date();

import java.util.Date;
public class exe8_1_1
{
static Athread threadA;
static Bthread threadB;
public static void main(String args[])
{
Thread threadA=new Thread(new Athread());
Thread threadB=new Thread(new Bthread());
threadA.start();
threadB.start();
}
}
class Athread implements Runnable
{
public void run()
{
for(int i=0;i<=3;i++)
{
Date timeNow = new Date();
System.out.println("A" + timeNow.toString());
try
{
Thread.sleep(2000);//改成这样sleep()是Thread类的静态方法
}
catch(InterruptedException e)
{
}
}
}
}
class Bthread implements Runnable
{
public void run()
{
for(int i=0;i<=5;i++)
{
Date timeNow = new Date();
System.out.println("B" + timeNow.toString());
try
{
Thread.sleep(1000);
}
catch(InterruptedException e)
{
}
}
}
}