java多线程问题(main函数中的thread已启动,后面的代码就不执行了)

元者风范 2013-11-25 01:41:23
package com.java.traffic;

import java.util.ArrayList;


public class ThreadTest2 {

public void runCar12(){
while(true){
System.out.println("runCar thread running");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

public static class Crun extends Thread{
ThreadTest2 c=null;
ArrayList<Light> lgts=null;
public Crun(ThreadTest2 c){
this.c=c;
}
public void run(){
c.runCar12();
}
}
public static void main(String[]args){
ThreadTest2 c=new ThreadTest2();
System.out.println("------------A");
Thread t=new Crun(c);
t.run();
System.out.println("------------B");

}
}


main函数中的thread已启动,后面的代码就不执行了
我是新手,这个问题奋战了一天了,望大神帮忙看一下……
...全文
1107 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
android_Y 2013-11-25
  • 打赏
  • 举报
回复
看书不认真吧,调用start启动线程
少羽 2013-11-25
  • 打赏
  • 举报
回复
main函数中的thread已启动,后面的代码就不执行了 我是新手,这个问题奋战了一天了,望大神帮忙看一下…… 亮了... ...
只是_曾经 2013-11-25
  • 打赏
  • 举报
回复
start()开启一个新线程,如果用run()想当于在住线程调用了一个方法。。
快乐的2 2013-11-25
  • 打赏
  • 举报
回复
引用 1 楼 huxiweng 的回复:
启动线程用t.start()
xiaomm627 2013-11-25
  • 打赏
  • 举报
回复
t.start(),not t.run()
genganpeng 2013-11-25
  • 打赏
  • 举报
回复
启动线程用start,run是一个方法
时光清浅 2013-11-25
  • 打赏
  • 举报
回复
楼主,启动线程是调用start()方法。 你直接t.run(),相当于方法调用。
teemai 2013-11-25
  • 打赏
  • 举报
回复
启动线程用t.start()

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧