More advanced thread tasks

We have seen the thread life cycle and its states, but threads also support some advanced tasks, such as sleeping, joining, and interrupting. Let's discuss them:

  • Sleeping: The sleep() thread method can be used to pause the execution of the current thread for the specified amount of time.
  • Joining: The join() thread method can be used to pause the execution of the current thread until the thread it joins completes its task.
  • Interrupting: The interrupt() thread method can be used to break out the sleeping or waiting state of the thread. It throws InterruptedException if the thread is in the sleeping or waiting state, otherwise, it doesn't interrupt the thread but sets the interrupted flag to true.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset