Video is locked.

Unlock the full course today

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

Parallel and Concurrent Programming with Java 2

Semaphore: Java demo

From the course: Parallel and Concurrent Programming with Java 2

Start my 1-month free trial
  • Course details

    With parallel computing, you can leverage multiple compute resources to tackle larger problems in a shorter amount of time. In this course, the second in the Parallel and Concurrent Programming with Java series, take a deeper dive into the key mechanisms for writing concurrent and parallel programs. Instructors Olivia and Barron Stone make these (often abstract) concepts down-to-earth, demonstrating key ideas using common kitchen activities. Learn all about synchronization, thread pools, asynchronous tasks, evaluating parallel performance, designing parallel programs, and more. Upon wrapping up this course, you'll have a solid understanding of how to parallelize a sequential program.


    • Click here to view Olivia Chiu Stone’s instructor page

      Olivia Chiu Stone

      Systems Engineer III at BLUE ORIGIN

      Olivia Chiu is a programmer and engineer who has always had a passion for learning how things work.

      She earned her bachelor's degree in engineering physics from Queen's University and her master's degree in mechanical engineering from McGill University. After university, she spent several years programming in LabVIEW and C# as a developer at National Instruments before becoming the project manager for the NI VeriStand development team. Outside of work, Olivia is passionate about educating and encouraging students, and dedicates her time to fostering our next generation of engineers.
    • Click here to view Barron Stone’s instructor page

      Barron Stone

      Engineer | Author | Veteran

      Barron Stone is an electrical engineer experienced in both low-level digital hardware and high-level software.

      He earned his bachelor of science in electrical engineering from Rice University and his master of science in electrical engineering from the Air Force Institute of Technology. He spent several years as an applications engineer and product-marketing engineer at National Instruments, where he developed marketing and training content for the FPGA-based NI FlexRIO modular instruments. Today, Barron is serving as an officer in the United States Air Force.

    Skills covered in this course

  • Learn parallel programming basics

    - [Instructor] For this Java example, I'll use a counting semaphore to control access and keep track of the number of available ports on a cell phone charger. This class named CellPhone has a static semaphore variable named charger on line nine, which I've initialized to have a value of four, representing the number of charger ports available to connect to. In the cell phone's run method, it will try to acquire the semaphore on line 17. If the semaphore is not available because its value is zero, then the thread will wait there until a charging port opens up and the semaphore is released. Once a cell phone thread has acquired the semaphore, it prints a message that it's charging and then sleeps for a random amount of time from one to two seconds. After that, the cell phone will execute the finally clause on line 22, which prints a message that it's done charging and then releases the semaphore to increment its value so another thread can acquire it. Down in the main method, I just use…

  • 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.

    Download the exercise files for this course. Get started with a free trial today.

  • Download courses and learn on the go

    Watch courses on your mobile device without an internet connection. Download courses using your iOS or Android LinkedIn Learning app.

    Watch this course anytime, anywhere. Get started with a free trial today.