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 是多久? 我想也许是一个时间片吧。再找找。。
当这个时间片用完的时候,这个线程暂时不执行,换到下个线程执行,然后再给
它分配个时间片,再执行.....
yield()方法就是,当代码执行到yield()时,即使给这个线程分配的时间片没有
用完也不继续执行了,让给下个线程.让下个线程开始执行
我想也许是一个时间片吧。再找找。。
但没有任何机制去保证它一定会被执行.
yield通常会使程序输出更加均匀.