日期:2014-05-19  浏览次数:20842 次

新手求问,关于线程的代码无法实现。
package example.text;

public class ThreadTextDemo {
public static void main(String[]args)
{
TestThread a=new TestThread();
new Thread(a).start();
for(int b=0;b<5;b++)
{
System.out.println("1");
}
}

}


class TestThread implements Runnable {
public void run(){
for(int a=0;a<5;a++){
System.out.println("2");
}
}
   public void talk()
   {
   System.out.println("3");
   }
}


输出:1111122222 为什么没创建起线程1212121212输出。
------最佳解决方案--------------------
执行太快,把循环改成500试试就可以了。具体和你的cpu和内存还有关系。