public final void wait(long timeout,int nanos) throws InterruptedException{
if(timeout<0){
throw new IllegalException("timeout value is negative");
}
if(nanos<0 || nanos > 999999){
throw new IllegalException("nanosecond timeout value out of range");
}
if(nanos>0){
timeout++;
}
wait(timeout);
}
package com.ruigege.threadFoundation1;
public class UserYieldMethod implements Runnable{
public UserYieldMethod() {
Thread thread = new Thread(this);
thread.start();
}
@Override
public void run() {
System.out.println("开始一个线程"+Thread.currentThread());
Thread.yield();
System.out.println("结束一个线程"+Thread.currentThread());
}
public static void main(String[] args) {
new UserYieldMethod();
new UserYieldMethod();
new UserYieldMethod();
}
}
https://github.com/ruigege66/ConcurrentJava