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 - Java Tutorial
From the course: Parallel and Concurrent Programming with Java 1
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…
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
-
-
-
-
Thread vs. process4m 36s
-
Thread vs. process: Java demo6m 48s
-
(Locked)
Concurrent vs. parallel execution4m 54s
-
(Locked)
Execution scheduling3m 38s
-
(Locked)
Execution scheduling: Java1m 57s
-
(Locked)
Thread lifecycle3m 36s
-
(Locked)
Thread lifecycle: Java demo4m 55s
-
(Locked)
Thread attributes: Java demo2m 22s
-
(Locked)
Runnable vs. thread: Java demo3m 53s
-
(Locked)
Daemon thread2m 49s
-
(Locked)
Daemon thread: Java demo2m 21s
-
-
-
-
-