标题: 关于多线程创建两种方式,继承和实现内存是怎么分布的, [打印本页] 作者: 李创 时间: 2012-3-16 10:02 标题: 关于多线程创建两种方式,继承和实现内存是怎么分布的, class Testextends extends Thread
{
private int x=10;
public void run()
{
while(x>0)
{
System.out.println(Thread.currentThread().getName()+" extends: "+x--);
}
}
}
class Testimplemets implements Runnable
{
private int y=10;
public void run()
{
while(y>0)
{
System.out.println(Thread.currentThread().getName()+" implements : "+y--);
}
}
}
class test
{
public static void main(String[] argv)
{
Testextends e1 = new Testextends();
Testextends e2 = new Testextends();
e1.start();
e2.start();
Testimplemets i = new Testimplemets();
Thread t1 = new Thread(i);
Thread t2 = new Thread(i);
t1.start();
t2.start();