初学多线程遇到的问题

ysrotciv ysrotciv 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
package C19;

public class ThreadDemo_1 {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
TestThread t = new TestThread();
new Thread(t).start();
// new TestThread2().start();
for(int i = 0; i < 10; i++){
System.out.println("main 线程在运行");
}


}

}

class TestThread implements Runnable{
public void run(){
for(int i = 0; i < 10; i++){
System.out.println("TestThread 在运行");
}
}
}
上面是书上给的例子,但是得不到"main 线程在运行"和"TestThread 在运行"交替出现的结果,请问是例子错了还是跟我的系统有关系
...全文
评论 4
收藏 已收藏
分享
返回顶部
ysrotciv
Java SE 62,620 成员 307,251 内容