Learn how to investigate the order in which several threads are scheduled to execute with an example Java program. Also, observe that the threads may execute in a different order each time the program runs.
- [Instructor] To demonstrate how scheduling can impact … execution, I've written this Java program that creates … two threads named Baron and Olivia … that continuously chop vegetables for about one second. … Each instance of the Vegetable Chopper class defined … on line five will run as a separate thread. … Inside of a classes run method, which is on line 14, … it uses a y loop that will continuously run as long … as the class variable name Chopping is true. … And for each loop iteration, it will print a message … and then increment the value of an instance variable … named Vegetable Count. … Down in the program's main method on line 23, … I instantiate two vegetable chopper threads named Baron … and Olivia and then I start them both chopping vegetables … at roughly the same time. … I let them both run for about one second … before setting the vegetable chopper classes variable … named Chopping to false on line 30 which stops them both. … Then finally at the end of the program, I print a message …
- 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.