java多線程中sleep()和join()的區(qū)別

          If the Sleep method is called with System.Threading.Timeout.Infinite passed in as the parameter, the thread will remain in the WaitSleepJoin state until a different thread wakes it by using the Interrupt method. Thread.Sleep(System.Threading.Timeout.Infinite)

          One reason you might want to do this is if a thread determines that it is in a state where the best thing it can do is nothing. This may be an alternative to ending the thread by using the Abort method, or simply exiting the thread’s method. Once a thread ends, there is no way to restart it. However, if a thread calls the Sleep method and passes in Infinite for the timeout value, it is possible to exit that state at a later time. This concept is similar to calling Join.

          When Join is called and no parameter is passed in, the current thread will wait indefinitely for the thread to end. When Join is called with a timeout value, the Join method will block for at most that period of time and then return a value indicating if the thread of interest ended. A key difference is that Join is called on a different thread while Sleep is called on the current thread. Join also causes the current thread to pause for a period of time, but with the idea that it is waiting for some other thread to terminate. At the point the thread being joined terminates, the Join method returns.

          posted on 2007-12-12 15:21 劉錚 閱讀(825) 評論(0)  編輯  收藏 所屬分類: JAVA General

          <2025年5月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          導航

          統(tǒng)計

          留言簿(1)

          文章分類(141)

          文章檔案(147)

          搜索

          最新評論

          主站蜘蛛池模板: 景宁| 张掖市| 侯马市| 太康县| 古蔺县| 全州县| 白城市| 安龙县| 新余市| 北京市| 邛崃市| 英吉沙县| 竹山县| 麻栗坡县| 乐东| 克什克腾旗| 沐川县| 吴堡县| 望都县| 汽车| 读书| 二连浩特市| 蓬莱市| 广汉市| 陆河县| 宁乡县| 颍上县| 南昌县| 阿拉善左旗| 延吉市| 张北县| 遵义市| 高邮市| 特克斯县| 柏乡县| 孝感市| 德令哈市| 沂源县| 宾川县| 宁河县| 海丰县|