Save this video free

UNC COMP 301 - F26/Lec 14 - Race conditions, Synchronized methods; Observer Design Pattern

Muhammad Sayeed Ghani · 1:14:56 · Watch on YouTube

Part of UNC Chapel Hill COMP 301. See all 22 lectures and search them

These notes were made with YouTube Collector. Paste any YouTube link and get the same: a summary, chapters and a searchable transcript.

Overview

The lecture concludes Java concurrency with thread scheduling, race conditions, synchronization, locks, and deadlocks, then introduces the Observer design pattern through a basketball-game example. The code examples show how shared counters can produce inconsistent results, how synchronized access protects them, and how a game subject registers and notifies fan observers when scores change.

Key takeaways

Chapters

0:00 Runnable Tasks, Lambdas, Threads, and join()
4:40 Why Thread.join() Can Throw InterruptedException
8:46 Operating-System Scheduling, Cores, and Context Switching
13:58 Race Conditions Require Shared State and Concurrent Access
16:10 Counter Example: Lost Updates from Increment and Decrement
26:56 Synchronized Methods Protect the Shared Counter
29:18 Locks, try-finally, and Reentrant Access
37:00 Deadlock from Opposing Lock Acquisition
44:00 Observer Pattern: Subjects, Observers, and Events
53:36 Observer Registration, Notification, and Pattern Terminology
57:36 Subject Implementation: Store and Update Observers
1:00:00 Game and Fan Interfaces Define the Observer Contract
1:03:00 Basketball Game State and Team-Specific Fan Observers
1:08:00 Observer Demo Output and UML Relationships

Keep these chapters and the full searchable transcript in your own library.

Transcript excerpt

0:00 So today we should be finishing off our topic on concurrent programming which we started last in the last lecture and uh we should be proceeding on to the next major topic which is the observer design pattern. So just to uh give you an idea as to how we're proceeding in terms of our original planned course overview. We are somewhat ahead as you can see. Uh we should be finishing off uh on concurrent programming today and we'll be continuing on with the observer design pattern. Uh that will probably place us a little bit ahead of the original schedule. In fact quite a bit. Um we will probably uh after the midterm we will probably go back and review some of the topics and go slightly deeper on

0:49 topics which we haven't completely covered exhaustively. So that's what my plan is. Uh unless you folks have any other suggestions for uh some of the extra lectures that we'll have at the end of the semester. Right? So uh let's go on and continue off with uh continue on with our topic from the last lecture which is concurrent programming. And I'll take a quick look at a couple of the examples that we spoke about in the last lecture. uh the first one being the uh method which was defined as multi-threading C option C and uh if you take a quick look at that particular example what we saw was uh we had a runnable task so just to make sure that people uh haven't

1:37 forgotten uh a runnable task is one which has the runnable is the interface and there is only one method defined in that interface Does anybody remember the name of the method? >> Yeah, >> run. >> That was run. Yeah, very simply that was

This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.

In this course

Related notes

Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Muhammad Sayeed Ghani.

Want the full transcript?

Save this video in YouTube Collector to get its complete searchable transcript, your own AI summaries, and a library that keeps every video you collect in one place.