From the course: Java Threads

Unlock the full course today

Join today to access over 24,400 courses taught by industry experts.

Interrupting a thread

Interrupting a thread - Java Tutorial

From the course: Java Threads

Interrupting a thread

- [Instructor] Interrupting a thread means indicating to the thread that it should stop what it's doing, interruptions are helpful when your program performs a long-running task in a thread. When a thread is in the middle of its execution the program might request a thread to finish doing its task early even if the task isn't complete, this could be because the program wants to terminate. It's something like a guest is dining at a restaurant and the waiter asks to take away the plate before the guest finishes the meal because they want to close the restaurant. When this happens the thread should respond to the interruption, it's up to you to decide how it should respond. Basically you need to make the thread running the task responsive to the interrupt request. The most common response would be to terminate itself, at the restaurant, the guest decides what to do. The guest could either leave or continue eating, most probably…

Contents