美文网首页
yield && sleep &&

yield && sleep &&

作者: ibyr | 来源:发表于2016-11-02 11:06 被阅读8次

    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. 
    

    相关文章

      网友评论

          本文标题:yield && sleep &&

          本文链接:https://www.haomeiwen.com/subject/fyevuttx.html