class ThreadDemo2 extends Thread//implements Runnable
{
private int thick =200;
public void run()
{
while(true)
{
if(thick>0)
System.out.println(Thread.currentThread().getName()+"===="+thick--);
//thick--;
}
}
}
/**
* @param args */
class ThreadDemo1
{
public static void main(String[] args)
{
ThreadDemo2 t = new ThreadDemo2();
Thread t1 = new Thread(t);
Thread t2 = new Thread(t);
Thread t3 = new Thread(t);
Thread t4 = new Thread(t);
t1.start();
t2.start();
t3.start();
t4.start();
}
}
以上代码,用继承Thread也实现了多线程功能,打印出线程数是从1到4。我换成实现接口后,发现线程数是从0到3
这意味着什么???两种方式的线程数分别是多少?主线程什么的都算上。高手勿喷 |