文档上说“Causes the currently executing thread object to temporarily pause and allow other threads to execute. ”,让其它线程执行,请问,让其它线程执行多久,本线程才能恢复执行?

解决方案 »

  1.   

    这么说吧,当有多个线程同时在执行的时候,每个线程都有它分配的时间片 
    当这个时间片用完的时候,这个线程暂时不执行,换到下个线程执行,然后再给 
    它分配个时间片,再执行..... 
    yield()方法就是,当代码执行到yield()时,即使给这个线程分配的时间片没有 
    用完也不继续执行了,让给下个线程.让下个线程开始执行
      

  2.   

    The call to the static method Thread.yield( ) inside run( ) is a suggestion to the thread scheduler (the part of the Java threading mechanism that moves the CPU from one thread to the next) that says, "I’ve done the important parts of my cycle and this would be a good time to switch to another task for a while." It’s completely optional,这是Thinking in java上的一句话,也没有说让其它线程执行多久,for a while 是多久? 
    我想也许是一个时间片吧。再找找。。
      

  3.   

    这个时间是你决定不了的,由jvm来定,yield就是让它暂停,把机会让给别的线程,但并不决定它什么时候继续执行,就像调用start也只能说线程即将执行,也不能保证它立刻执行
      

  4.   

    yield是线程让步,让CPU集中精力执行其他线程,等到空闲时再执行该线程
      

  5.   

    yield是让出当前线程对cpu的占有权。是挂起当前线程,执行其他线程的最佳时机。通常情况下,在当前线程的主要工作完成以后调用,以表示可以被挂起了。不过具体会不会被挂起或者挂起多长时间,需要根据不同的虚拟你或机器调度机制而定。
      

  6.   

    时间是由jvm决定的,上面说的很清楚了。
      

  7.   

    这个没有标准,JAVA虚拟机会从线程池中随机抽取一个线程执行。
      

  8.   

    yield是让步的意思,使用yield()表示当你觉的某个线程工作执行的差不多了,让别人线程获得执行机会.
    但没有任何机制去保证它一定会被执行.
    yield通常会使程序输出更加均匀.
      

  9.   

    你开发手机应用么?一般目前>1.5都用concurrent开发。