import java.util.Random;
class A extends Thread
{
int i=1;
Random r=new Random();
public void run()
{
while(i<100)
{
System.out.println("奇数:"+i);
i+=2;
try
{
Thread.sleep(r.nextInt(500));
}
catch(InterruptedException e)
{
e.printStackTrace();
};
}
}
}
class B implements Runnable
{
int i=2;
Random r=new Random();
public void run()
{
while(i<=100)
{
System.out.println("偶数:"+i);
i+=2;
try
{
Thread.sleep(r.nextInt(500));
}
catch(InterruptedException e)
{
e.printStackTrace();
}
}
}
}
public class TestThread
{
public static void main(String[] args)
{
new A().start();
new Thread(new B()).start();
}
}
这个我可以给你写哦,主要是线程间同步与互斥。RUNNABLE接口实现及thread继承