本帖最后由 xiaochen33520 于 2014-1-26 20:39 编辑
class ThreadDemo2 implements Runnable
{
static String name;
public ThreadDemo2(String name)
{
this.name = name;
}
public void run()
{
for(int x = 0;x<10;x++)
{
System.out.println("...."+x+"...."+Thread.currentThread().getName());
}
}
public static void main(String[] args)
{
ThreadDemo2 d = new ThreadDemo2("张三");
ThreadDemo2 d2 = new ThreadDemo2("李四");
System.out.println(d.name);
System.out.println(d2.name);
Thread t1 = new Thread(d,d.name);
Thread t2 = new Thread(d2,d2.name);
t1.start();
t2.start();
}
}
为什么两个线程的名字都是李四?
|