PA1 Discussion.

Slides:



Advertisements
Similar presentations
13/04/2015Client-server Programming1 Block 6: Threads 1 Jin Sa.
Advertisements

Concurrency Important and difficult (Ada slides copied from Ed Schonberg)
Ade Azurat, Advanced Programming 2004 (Based on LYS Stefanus’s slides) Advanced Programming 2004, Based on LYS Stefanus’s slides Slide 2.1 Multithreading.
Multithreaded Programs in Java. Tasks and Threads A task is an abstraction of a series of steps – Might be done in a separate thread – Java libraries.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 5 Multithreading and.
Threads Load new page Page is loading Browser still responds to user (can read pages in other tabs)
Java Threads Part II. Lecture Objectives To understand the concepts of multithreading in Java To be able to develop simple multithreaded applications.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L19 (Chapter 24) Multithreading.
Multithreading A thread is the flow of execution, from beginning to end, of a task in a program. With Java, you can launch multiple threads from a program.
Concurrency CS 510: Programming Languages David Walker.
Java ThreadsGraphics Programming Graphics Programming: Java Threads.
Multithreading.
Threading in Java – a Tutorial QMUL IEEE SB. Why Threading When we need to run two tasks concurrently So multiple parts (>=2) of a program can run simultaneously.
Discussion Week 3 TA: Kyle Dewey. Overview Concurrency overview Synchronization primitives Semaphores Locks Conditions Project #1.
1 Advanced Computer Programming Concurrency Multithreaded Programs Copyright © Texas Education Agency, 2013.
Chapter 15 Multithreading F Threads Concept  Creating Threads by Extending the Thread class  Creating Threads by Implementing the Runnable Interface.
Threads in Java. History  Process is a program in execution  Has stack/heap memory  Has a program counter  Multiuser operating systems since the sixties.
Threading and Concurrency Issues ● Creating Threads ● In Java ● Subclassing Thread ● Implementing Runnable ● Synchronization ● Immutable ● Synchronized.
Multi-Threaded Application CSNB534 Asma Shakil. Overview Software applications employ a strategy called multi- threaded programming to split tasks into.
Multithreading in Java Project of COCS 513 By Wei Li December, 2000.
111 © 2002, Cisco Systems, Inc. All rights reserved.
Practical OOP using Java Basis Faqueer Tanvir Ahmed, 08 Jan 2012.
1 Web Based Programming Section 8 James King 12 August 2003.
Concurrent Programming and Threads Threads Blocking a User Interface.
Laboratory - 4.  Threading Concept  Threading in.NET  Multi-Threaded Socket  Example.
Multithreading Chapter Introduction Consider ability of human body to ___________ –Breathing, heartbeat, chew gum, walk … In many situations we.
15.1 Threads and Multi- threading Understanding threads and multi-threading In general, modern computers perform one task at a time It is often.
© Wang Bin 2004 Java Threads. © Wang Bin 2004 In this lesson, you will learn to: u Define the concepts of threads and multithreading  Identify the functions.
Multi-Threading in Java
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 4: Threads.
Multithreaded Programming in Java David Meredith Aalborg University.
CSC 480 Software Engineering Lab 2 – Multi-Threading Oct 18, 2002.
Chapter 13: Multithreading The Thread class The Thread class The Runnable Interface The Runnable Interface Thread States Thread States Thread Priority.
CSC CSC 143 Threads. CSC Introducing Threads  A thread is a flow of control within a program  A piece of code that runs on its own. The.
Software Design 13.1 From controller to threads l Threads are lightweight processes (what’s a process?)  Threads are part of a single program, share state.
Multi player client sever Snake Game Technology : JAVA (swing for user interface and Socket for passing coordinates of snakes, food item and score)
Java Thread Programming
OPERATING SYSTEM CONCEPT AND PRACTISE
Threads in Java Two ways to start a thread
Multithreading / Concurrency
Chapter 4: Threads.
Chapter 13: Multithreading
Multi Threading.
Multithreading.
Multithreaded Programming in Java
Chapter 2 Processes and Threads Today 2.1 Processes 2.2 Threads
Chapter 5: Threads Overview Multithreading Models Threading Issues
Object-Orientated Analysis, Design and Programming
Lecture 21 Concurrency Introduction
Multithreading in Java
Multithreading Chapter 23.
Chapter 4: Threads.
CNT 4007C Project 2 Good morning, everyone. In this class, we will have a brief look at the project 2. Project 2 is basically the same with project 1.
Threads and Multithreading
Multithreading.
Multithreading.
Threads and Multithreading
Concurrency in Java Last Updated: Fall 2010 Paul Ammann SWE 619.
CHAPTER 4:THreads Bashair Al-harthi OPERATING SYSTEM
Chapter 15 Multithreading
COMPONENTS – WHY? Object-oriented source-level re-use of code requires same source code language. Object-oriented source-level re-use may require understanding.
NETWORK PROGRAMMING CNET 441
MULTITHREADING PROGRAMMING
Threads and Multithreading
Lecture 19 Threads CSE /6/2019.
Multithreaded Programming in Java
CMSC 202 Threads.
some important concepts
Java Chapter 3 (Estifanos Tilahun Mihret--Tech with Estif)
Threads and concurrency / Safety
Presentation transcript:

PA1 Discussion

Today Review Multithreading in Java Discuss Client-Server Architecture Some Hints on PA1

Thread Concepts A program may consist of many tasks that can run concurrently. A thread is the flow of execution of a task.

Thread Concepts In Java, each task is an instance of the Runnable interface, also called a runnable object. A thread is essentially an object that facilitates the execution of a task.

Thread Concepts When your program executes as an application, the Java interpreter starts a thread for main method. You can create additional threads to run concurrent tasks. Task 1: print the letter “a” 50 times Task 2: print the letter “b” 50 times Task 3: print the integers 1 through 50 Example 1: TestThread1.java

Thread Concepts Another way to create a multithreading program is to define a class that extends class Thread and implements the run() method.

Thread Concepts We will take this approach for PA1! Another way to create a multithreading program is to define a class that extends class Thread and implements the run method. Task 1: print letter “z” 50 times Task 2: print integers 1 through 50 Example 2: TestThread2.java

Thread Synchronization A shared resource may become corrupted if it is accessed simultaneously by multiple threads. To avoid race conditions, it is necessary to prevent more than one thread from simultaneously entering a certain part of the program. The keyword synchronized: acquire a lock of an object or class first before executing a block of code or a method. Example 3: TestThread3.java

Part I: Writing a Client-Server Application #status I just woke up! #statusPosted User User input: I just woke up!

Part II: Implementing a Broadcast Status Update Using Multi-threading How does the server manage multiple clients? How does each user broadcast messages?

Part III: Adding Friendship / Multicast Capability to the Social Media App private final userThread[] threads; ArrayList<String> friends = new ArrayList<String>(); ArrayList<String> friendrequests = new ArrayList<String>(); //keep track of sent friend requests