Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CSC364 Lecture 17

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.

CSC364 Lecture 17

Final Review
(202605)

Avatar for Javier Gonzalez-Sanchez

Javier Gonzalez-Sanchez PRO

March 10, 2026
Tweet

Transcript

  1. Dr. Javier Gonzalez-Sanchez [email protected] www.javiergs.info o ffi ce: 14 -227

    CSC 364 Introduction to Networked, Distributed, and Parallel Computing Lecture 17. Final Review 1
  2. 2 Grading Assignments L a bs + Quizzes Attend a

    nce & P a rticip a tion 20% 30% 10% 100% Project Fin a l Project Fin a l Ex a m 5% 20% Peer Ev a lu a tion 15%
  3. 3 Grading >= 96.5 A >= 93 A- >= 89.5

    B+ >= 86 B >= 82.5 B- >= 79 C+ >= 75.5 C >= 72 C- >= 68.5 D+ >= 65 D >= 61.5 D- < 61.5 F
  4. 4 Disclaimer for Final Exam Review The f in a

    l ex a m is comprehensive, encomp a ssing a ll course m a teri a ls. This review covers only a subset of topics. Import a nt: Ensure you review a ll lecture slides a nd course m a teri a ls. The following slides include ex a mples rel a ted to selected topics. This is NOT a n exh a ustive list of ex a m topics.
  5. 6 Key Topics Introduction to computing p a r a

    digms: • Networked Computing • Distributed Computing • P a r a llel Computing Systems sc a le beyond a single progr a m running on a single m a chine. Modern softw a re systems a re not just progr a ms but inter a cting components. Project-b a sed a ppro a ch, where concepts a re a pplied through progr a mming a ssignments.
  6. 8 Client–Server Communication • Sockets provide a communic a tion

    ch a nnel • Ports • IP Address • DNS Address • loc a lhost • Client–server model: (1) Cre a te a socket, (2) Bind the socket to a port, (3) Listen for connections, (4) Accept a client connection, (5) Send/receive d a t a
  7. 9 Client–Server Communication ServerSocket server = new ServerSocket(port); Socket client

    = server.accept(); InputStream in = client.getInputStream(); OutputStream out = client.getOutputStream();
  8. 10 Client–Server Communication (5 points) Write a server program that

    sends the string 012345 to every client that connects. (5 points) Write a client program that connects to the server and receives the string 012345.
  9. 11 Key Ideas • Protocols • TCP provides reli a

    ble communic a tion through byte stre a ms. • TCP Connections follow a lifecycle: connect → communic a te → close. • Systems m a y use short-lived or persistent connections. • Wh a t is HTTP? • HTTP request • HTTP response • URL - http://loc a lhost:8080/?n a me=J a vier&course=CSC364
  10. 13 HTTP Server ServerSocket server = new ServerSocket(8080); while(true) {

    Socket client = server.accept(); BufferedReader in = new BufferedReader( new InputStreamReader(client.getInputStream())); PrintWriter out = new PrintWriter(client.getOutputStream()); String request = in.readLine(); out.println("HTTP/1.1 200 OK"); out.println("Content-Type: text/plain"); out.println(); out.println("Hello from my Java Web Server”); client.close(); }
  11. 14 HTTP Communication (10 points) Use an HTTP connection (Java

    code) to get the content of the page http://xyz.com
  12. 15 Key Idea User types URL | v DNS lookup

    | v IP address | v TCP Socket Connection | v HTTP Request | v Server Application Logic | v HTTP Response | v Browser renders page
  13. 17 Key Ideas - how systems c a n decouple

    producers of inform a tion from consumers of inform a tion, a llowing components to communic a te without direct knowledge of e a ch other. - Broker (or mess a ge ch a nnel) - Topics
  14. 18 MQTT MqttClient client = new MqttClient("tcp://localhost:1883", "publisher"); client.connect(); client.publish(

    "class/announcements", new MqttMessage("Exam tomorrow".getBytes())); MqttClient client = new MqttClient("tcp://localhost:1883", "subscriber"); client.connect(); client.subscribe( "class/announcements", (topic, msg) -> {println(new String(msg.getPayload()));} );
  15. 20 Key Ideas Wh a t is a Thre a

    d? Wh a t is a Process? Wh a t is a Progr a m?
  16. 21 Runnable class ClientHandler implements Runnable { private Socket client;

    public ClientHandler(Socket client) { this.client = client; } public void run() { handleClient(client); } } new Thread(new ClientHandler(client)).start();
  17. 22 Runnable (10 points) Implements the method handleClient. It creates

    a new thread (Worker) to take care of the new client. Implement the class Worker also. ServerSocket server = new ServerSocket(port); while (true) { Socket client = server.accept(); handleClient(client); }
  18. 23 Key Ideas - Cre a ted a new thre

    a d for every client connection or h a ve a Pool - Thre a d explosion - Thre a d Pools - Java Executor Framework
  19. 25 Thread Pool (10 points) Re-implements the method handleClient (from

    a former question) using a thread pool: ServerSocket server = new ServerSocket(port); while (true) { Socket client = server.accept(); handleClient(client); }
  20. 27 Semaphore Semaphore semaphore = new Semaphore(3); semaphore.acquire(); try {

    // access resource } finally { semaphore.release(); }
  21. 28 Key Ideas • Wh a t is a "r

    a ce condition”? • Wh a t is a “de a dlock”? • Wh a t is a “critic a l section”? • synchroniz a tion a nd (synchroniz a tion keyword in J a v a ) • locks vs. sem a phores • concurrent d a t a structures
  22. 30 Push and Pull Models Pull: Client ----request----> Server Client

    <---response---- Server Push: Producer ----event----> Subscriber Producer ----event----> Subscriber Producer ----event----> Subscriber
  23. 31 Key Ideas • Concurrency design p a tterns provide

    structured solutions for coordin a ting thre a ds. • The Producer–Consumer p a ttern sep a r a tes d a t a gener a tion from processing. Producer → Bu ff er → Consumer • The Re a ders–Writers p a ttern m a n a ges concurrent a ccess to sh a red resources. Re a ders → sh a red resource ← Writers • Pipeline a rchitectures divide work into p a r a llel st a ges. Pipeline: St a ge 1 → St a ge 2 → St a ge 3 → St a ge 4 • Inmut a ble Objects
  24. 32 Question(s) 1. Wh a t concurrency problem m a

    y occur? 2. Expl a in why the f in a l v a lue might not be 20000. 3. Rewrite increment() to m a ke it thre a d- s a fe using synchronized.
  25. 33 Question(s) 1. Why is this implement a tion ine

    ff icient for m a ny re a ders? 2. Which concurrency p a ttern should be used here? 3. Implement it
  26. 34 Question (10 points) You are designing a system where:

    • multiple sensors generate data continuously • several worker threads analyze the data • a monitoring dashboard must update whenever new results appear. Questions: 1. Which concurrency pattern should connect sensors and workers? 2. Which pattern should be used by the dashboard? 3. Draw a simple architecture diagram.
  27. 38 Question Question 1: Complete the run() method of the

    Re a der cl a ss so th a t it: • repe a tedly selects a r a ndom course code from codes • c a lls re a dCourse • prints the result • sleeps for 1000 ms Question 2: Using the s a me CourseC a t a log, complete the Writer cl a ss so th a t it: • upd a tes "CSC364" • writes "P a r a llel Computing v" + version • increments the version • sleeps for 3000 ms
  28. 39 Question Question 3 (identify beh a vior) Suppose the

    progr a m cre a tes: • 5 re a der thre a ds • 2 writer thre a ds Answer the following: 1. C a n multiple re a ders run a t the s a me time? 2. C a n two writers upd a te the c a t a log a t the s a me time? 3. C a n a re a der a ccess the c a t a log while a writer holds the write lock?
  29. 40 Top 20% Event-Driven Architecture (Blackboard) GUI in Java +

    Drawing Threads Listeners (for user input) Assignments and Final Project
  30. CSC 364 Introduction to Introduction to Networked, Distributed, and Parallel

    Computing Javier Gonzalez-Sanchez, Ph.D. [email protected] Winter 2026 Copyright. These slides can only be used as study material for the class CSC 364 at Cal Poly. They cannot be distributed or used for another purpose. 44