问答详情
源自:4-2 volatile不能保证原子性(上)

Thread.activeCount()运行出错问题

......

    System.out.println(Thread.activeCount());

    while (Thread.activeCount() > 1) {

      Thread.yield();

    }


    System.out.println(t.getNum());

按照教程中写的代码

打印结果:

877

1000

FATAL ERROR in native method: JDWP cannot get thread local storage, jvmtiError=JVMTI_ERROR_WRONG_PHASE(112)

JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): cannot get thread local storage [../../../src/share/back/threadControl.c:195]


为什么有警告输出?


提问者:Felix_He 2015-04-13 09:23

个回答

  • RainbowPeter
    2016-01-14 23:49:38

    你代码写错了哦,while(Thread.activeCount() < 1),是活跃的线程数量小于1,你写成大于号啦