yield is just a suggestion to give up CPU for other threads, JVM may be not accept the suggestion. Not suggesting to use yield more than debug level.
sleep gets to let current thread give up CPU for other threads, JVM will executes its order as command.
join is to make current thread wait a sub-thread(or sub-threads) finishing running, and the current thread that invokes the sub-thread is blocked.
public class Main {
public void main(String[] args){
Thread thread1 = new Thread();
thread1.start();
thread1.join(); // join
}
}
// Then main thread will wait for thread1 finishing running,
// then main thread starts to run again.
网友评论