当前位置: 代码迷 >> J2EE >> 生手求问,关于线程的代码无法实现
  详细解决方案

生手求问,关于线程的代码无法实现

热度:112   发布时间:2016-04-22 00:14:45.0
新手求问,关于线程的代码无法实现。
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和内存还有关系。
  相关解决方案