Join David Gassner for an in-depth discussion in this video Interrupting a thread, part of Advanced Java Programming (2012).
When you run a secondary thread, it will run to completion or until an exception occurs…or when you explicitly interrupt it from the process that created it.…I'll show you how to do this explicit interruption in the project Interrupt Thread.…This Main class creates an instance of a class called MyThread and then starts the thread.…And in that thread there is a loop that's outputting something to the command line once per second.…I'll execute that application, and you'll see the output of destroying from secondary…thread five times, and then the application finishes on its own.…
Now I'm going to go back and make one little change to the custom thread.…Instead of outputting an error, I'm going to design this to expect an interruption.…Within the catch block that's executed when an interrupted exception is thrown, I'll output…the text Thread interrupted.…I'll save that change and come back to the Main class.…Now within the Main class, I'm going to add a sleep command, I'll call Thread.sleep,…
- Installing Java on Windows and Mac OS X
- Installing Eclipse
- Using new features such as simplified generics
- Working with advanced class structures (member, local inner, etc.)
- Using the Reflection API
- Navigating inheritance trees
- Managing unordered and ordered sets
- Peeking and polling with queues
- Testing and error handling
- Managing files and directories
- Working with I/O streams
- Next steps with Java
Skill Level Advanced
1. Getting Started
2. Java 7 New Features
3. Using Advanced Class Structures
4. Using the Reflection API
5. More of the Collections Framework
6. Testing and Advanced Exception Handling
Using the finally keyword5m 40s
7. Managing Files and Directories in Java 7
8. Working with I/O Streams
9. Working with Multi-threading
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.