主题:问个问题,有代码,很短很小
现在看到了多线程,有个例子,如下。CountingThread 类就是个计数的类。ThreadTest创建了3个线程
public class ThreadTest
{
public static void main(String args[])
{
System.out.println("Thread started.");
CountingThread thread1=new CountingThread();
thread1.start();
CountingThread thread2=new CountingThread();
thread2.start();
CountingThread thread3=new CountingThread();
thread3.start();
}
}
public class CountingThread extends Thread
{
public void run()
{
System.out.println("Thread started:"+[color=FF0000]this[/color]);
for(int i=0;i<9;i++)
{
System.out.print("i="+(i+1)+"\t");
}
System.out.println("Thread stopped:"+this);
}
}
现在想问个问题 ,被我标记为彩色部分的那个+this是什么意思啊。
输出结果是:
Thread started.
Thread started:Thread[Thread-1,5,main]
Thread started:Thread[Thread-0,5,main]
Thread started:Thread[Thread-2,5,main]
i=1 i=2 i=3 i=4 i=5 i=6 i=7 i=8 i=9 Thread stopped:Thread[Thread-2,5,main]
i=1 i=2 i=3 i=4 i=5 i=6 i=7 i=8 i=9 Thread stopped:Thread[Thread-0,5,main]
i=1 i=2 i=3 i=4 i=5 i=6 i=7 i=8 i=9 Thread stopped:Thread[Thread-1,5,main]
public class ThreadTest
{
public static void main(String args[])
{
System.out.println("Thread started.");
CountingThread thread1=new CountingThread();
thread1.start();
CountingThread thread2=new CountingThread();
thread2.start();
CountingThread thread3=new CountingThread();
thread3.start();
}
}
public class CountingThread extends Thread
{
public void run()
{
System.out.println("Thread started:"+[color=FF0000]this[/color]);
for(int i=0;i<9;i++)
{
System.out.print("i="+(i+1)+"\t");
}
System.out.println("Thread stopped:"+this);
}
}
现在想问个问题 ,被我标记为彩色部分的那个+this是什么意思啊。
输出结果是:
Thread started.
Thread started:Thread[Thread-1,5,main]
Thread started:Thread[Thread-0,5,main]
Thread started:Thread[Thread-2,5,main]
i=1 i=2 i=3 i=4 i=5 i=6 i=7 i=8 i=9 Thread stopped:Thread[Thread-2,5,main]
i=1 i=2 i=3 i=4 i=5 i=6 i=7 i=8 i=9 Thread stopped:Thread[Thread-0,5,main]
i=1 i=2 i=3 i=4 i=5 i=6 i=7 i=8 i=9 Thread stopped:Thread[Thread-1,5,main]