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 - 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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
Pausing execution of a thread3m 52s
-
(Locked)
Interrupting a thread5m 42s
-
(Locked)
Implementing thread interruptions6m 13s
-
(Locked)
Making a thread to wait until another thread terminates5m 39s
-
(Locked)
Other useful methods of the Thread class2m 42s
-
(Locked)
Challenge: Webinar polling system1m 53s
-
(Locked)
Solution: Webinar polling system5m 9s
-
(Locked)
-