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.