Thread.yield()方法的官方解释是:暂停线程进而去执行其他线程.其中其他线程也包含自己当前的线程.例如
package snippet;
class MyThread extends Thread {
public MyThread(String name) {
setName(name);
}
@Override
public void run() {
System.out.println(getName());
yield();
System.out.println(getName());
}
}
public class test {
public static void main(String[] args) throws Exception {
MyThread t1 = new MyThread("aaa");
MyThread t2 = new MyThread("b");
t1.start();
t2.start();
}
}
暂时不知道这东西有什么用...