首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

为何这个程序中的睡眠状态不执行,应该打印出来是0514233241

2012-10-10 
为什么这个程序中的睡眠状态不执行,应该打印出来是0514233241package aclass Test3 implements Runnable

为什么这个程序中的睡眠状态不执行,应该打印出来是0514233241
package a;


 class Test3 implements Runnable {
  public void run()
  {
  for(int i =0;i<5;i++)
  { System.out.println( i );
  try{ Thread.sleep(50);
  }catch(InterruptedException e){
  e.printStackTrace();
  }}
}}
class Test2 implements Runnable{
public void run()
{for(int i=5;i>0;i--){
  System.out.println( i);
  try{ Thread.sleep(50);
  }catch(InterruptedException e){
  e.printStackTrace();
  }}
 }
}
public class Test1{
public static void main(String args[]){
  Test3 lx =new Test3();
  Test2 lx1 = new Test2();
  Thread t1 = new Thread(lx);
  Thread t2 = new Thread(lx1);
  t1.run();
  t2.run();}
}

[解决办法]
线程启动:
t1.start();
t2.start();

热点排行