Learn how to differentiate between threads and runnables in Java in this video. Discover that Thread is an abstract class which can be inherited, whereas Runnable is an interface which can be implemented. Learn how to recognize the pros and cons of each and when to use them.
- [Instructor] There are multiple ways … to create and run a Thread in Java. … One way is to extend the Thread class, … which is what I've been doing so far in this course. … When you subclass Thread, you can override … its run method to provide your own … custom code for the Thread to execute. … Then, you can create instances of your subclass, … and run them as Threads. … The other approach is to use the Thread constructor method … and pass a Runnable object as its target. … Runnable is the interface that a class … will need to implement if it will be executed by a Thread. … In fact, the Thread class itself … implements the Runnable interface. … Defining a class that implements the Runnable interface … simply requires you to have a run method, … similar to the run method that we override … when extending the Thread class. … To demonstrate how similar it is … to use the Thread class versus the Runnable interface, … I'll modify this program, which is based … on the previous example to demonstrate …
- Parallel vs. sequential computing
- Shared vs. distributed memory
- Execution scheduling
- Thread lifecycle
- Mutual exclusion
- Synchronized methods
- Checking for liveness
Skill Level Advanced
Java Essential Training: Objects and APIswith David Gassner2h 46m Intermediate
Java Essential Training: Syntax and Structurewith David Gassner3h 9m Intermediate
1. Parallel Computing Hardware
2. Threads and Processes
3. Mutual Exclusion
- 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.