From the course: Parallel and Concurrent Programming with Java 1

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Execution scheduling: Java

Execution scheduling: Java - Java Tutorial

From the course: Parallel and Concurrent Programming with Java 1

Start my 1-month free trial

Execution scheduling: Java

- [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 that indicates how many…

Contents