A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

和毕老师的创建线程代码一样,但是没有老师那种交替抢占CPU资源的效果,为什么...求解(我用的是myeclipse8.5编译的,是不是我这个集成环境有问题呀?)
  1. class test extends Thread{
  2.         public void run(){
  3.                 for(int i=0; i<60; i++){
  4.                         System.out.println("test run..."+i);
  5.                 }
  6.         }
  7. }

  8. public class ThreadDemo {

  9.         public static void main(String[] args){
  10.                 test t = new test();
  11.                 t.start();
  12.                 for(int i = 0;i < 60; i++){
  13.                         System.out.println("main run..."+i);
  14.                 }
  15.         }
  16. }
复制代码
下面是我的允许结果:
main run...0
main run...1
main run...2
main run...3
main run...4
main run...5
main run...6
main run...7
main run...8
main run...9
main run...10
main run...11
main run...12
main run...13
main run...14
main run...15
main run...16
main run...17
main run...18
main run...19
main run...20
main run...21
main run...22
main run...23
main run...24
main run...25
main run...26
main run...27
main run...28
main run...29
main run...30
main run...31
main run...32
main run...33
main run...34
main run...35
main run...36
main run...37
main run...38
main run...39
main run...40
main run...41
main run...42
main run...43
main run...44
main run...45
main run...46
main run...47
main run...48
main run...49
main run...50
main run...51
main run...52
main run...53
main run...54
main run...55
main run...56
main run...57
main run...58
main run...59
test run...0
test run...1
test run...2
test run...3
test run...4
test run...5
test run...6
test run...7
test run...8
test run...9
test run...10
test run...11
test run...12
test run...13
test run...14
test run...15
test run...16
test run...17
test run...18
test run...19
test run...20
test run...21
test run...22
test run...23
test run...24
test run...25
test run...26
test run...27
test run...28
test run...29
test run...30
test run...31
test run...32
test run...33
test run...34
test run...35
test run...36
test run...37
test run...38
test run...39
test run...40
test run...41
test run...42
test run...43
test run...44
test run...45
test run...46
test run...47
test run...48
test run...49
test run...50
test run...51
test run...52
test run...53
test run...54
test run...55
test run...56
test run...57
test run...58
test run...59

5 个回复

倒序浏览
多试几次,换个编译器试试
回复 使用道具 举报
代码没有问题,你把循环的次数变的大一些。我试了一下,100都不保险,你换成500就成。
回复 使用道具 举报
左建飞 发表于 2012-8-6 10:25
代码没有问题,你把循环的次数变的大一些。我试了一下,100都不保险,你换成500就成。 ...

谢啦...还真的是这样的原因,看来CPU运行的太快了!
回复 使用道具 举报
问题已解决!
回复 使用道具 举报
你的次数太少了~~cpu的运行速度很快的~~你把次数变大~~效果就出来了~~
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马