Animate objects and threads

Slides:



Advertisements
Similar presentations
June 1, 2000 Object Oriented Programming in Java (95-707) Java Language Basics 1 Lecture 6 Object Oriented Programming in Java Language Basics Objects.
Advertisements

Java Threads Part II. Lecture Objectives To understand the concepts of multithreading in Java To be able to develop simple multithreaded applications.
Slides prepared by Rose Williams, Binghamton University Chapter 20 Java Threads Part II.
CS220 Software Development Lecture: Multi-threading A. O’Riordan, 2009.
Slides prepared by Rose Williams, Binghamton University ICS201 Lectures 18 : Threads King Fahd University of Petroleum & Minerals College of Computer Science.
Java ThreadsGraphics Programming Graphics Programming: Java Threads.
Threads II. Review A thread is a single flow of control through a program Java is multithreaded—several threads may be executing “simultaneously” If you.
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.
50.003: Elements of Software Construction Week 5 Basics of Threads.
Fundamentals of Software Development 1Slide 1 Outline Designing a computational community for WordGamesDesigning a computational community for WordGames.
What is Concurrent Programming? Maram Bani Younes.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
Collage of Information Technology University of Palestine Advanced programming MultiThreading 1.
Silberschatz, Galvin and Gagne ©2011Operating System Concepts Essentials – 8 th Edition Chapter 4: Threads.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Implementing Processes and Process Management Brian Bershad.
University of Sunderland Java Threading, Mutex and Synchronisation Lecture 02 COMM86 Concurrent and Distributed Software Systems.
CGS 3763 Operating Systems Concepts Spring 2013 Dan C. Marinescu Office: HEC 304 Office hours: M-Wd 11: :30 AM.
Operating Systems Lecture 2 Processes and Threads Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing Liu School of.
REVIEW On Friday we explored Client-Server Applications with Sockets. Servers must create a ServerSocket object on a specific Port #. They then can wait.
Java Threads 11 Threading and Concurrent Programming in Java Introduction and Definitions D.W. Denbo Introduction and Definitions D.W. Denbo.
The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of.
E X C E E D I N G E X P E C T A T I O N S OP SYS Linux System Administration Dr. Hoganson Kennesaw State University Operating Systems Functions of an operating.
Concurrent Programming and Threads Threads Blocking a User Interface.
Session 16 Pinball Game Construction Kit:. Pinball Version 1 Replaced the fire button with a mouse event. Multiple balls can be in the air at once. –Uses.
Multithreading in Java Sameer Singh Chauhan Lecturer, I. T. Dept., SVIT, Vasad.
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 Reusing threads.
CSE 331 Software Design & Implementation Hal Perkins Autumn 2012 Event-Driven Programming 1.
Scis.regis.edu ● CS-434: Object-Oriented Programming Using Java Week 8 Dr. Jesús Borrego Adjunct Faculty Regis University 1.
Java Thread and Memory Model
Session 13 Pinball Game Construction Kit (Version 3):
08 Encapsulation and Abstraction. 2 Contents Defining Abstraction Levels of Abstraction Class as Abstraction Defining a Java Class Instantiating a Class.
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
Operating System Concepts Three User Interfaces Command-line Job-Control Language (JCL) Graphical User Interface (GUI)
Chapter 7 Classes and Methods III: Static Methods and Variables Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition)
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 4: Threads.
Swing Threading Nested Classes COMP 401 Fall 2014 Lecture 23 11/25/2014.
An operating system for a large-scale computer that is used by many people at once is a very complex system. It contains many millions of lines of instructions.
Process Scheduling In multiprogramming systems, when there is more than one ready process, the operating system must decide which one to activate. The.
Lecture 5. Example for periority The average waiting time : = 41/5= 8.2.
1.1 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 1: Introduction What Operating Systems Do √ Computer-System Organization.
Processes and threads.
Introduction to Eclipse
The Bouncing Ball Problem (Independent Threads)
MSc/ICY Software Workshop , Semester 2
Processes and Threads Processes and their scheduling
SE-2811 Software Component Design
Chapter 2 Processes and Threads Today 2.1 Processes 2.2 Threads
Chapter 19 Java Never Ends
CSC369 – tutorial 6: Midterm review
PC02 Term 1 Project Basic Messenger. PC02 Term 1 Project Basic Messenger.
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Chapter 4: Threads.
Realizing Concurrency using Posix Threads (pthreads)
Android Programming Lecture 8
Realizing Concurrency using the thread model
Threads and Multithreading
Processor Fundamentals
What is Concurrent Programming?
Android Topics UI Thread and Limited processing resources
Lecture Topics: 11/1 General Operating System Concepts Processes
Event loops 17-Jan-19.
Processes and Process Management
What is Concurrent Programming?
Realizing Concurrency using Posix Threads (pthreads)
CS703 – Advanced Operating Systems
Realizing Concurrency using the thread model
Event loops.
Expanding the PinBallGame
Repetition CSC 1051 – Data Structures and Algorithms I Course website:
Presentation transcript:

Animate objects and threads Outline: What is an animate object? What is a Thread? How are animate objects and Threads related? Apply these ideas: Paper-and-pencil exercise Threads program example Fundamentals of Software Development I Lecture 20

Animate objects Consider the following objects… Counter Timer Has state and behavior Doesn’t do anything unless someone asks it to do so using its increment or reset method Timer Has state and behavior, much like a Counter Has a traditional, passive reset method But a Timer acts by itself! Its increment method is called by the Timer itself on a regular basis. Animate object Fundamentals of Software Development I Lecture 20

Threads In Day 1 we saw two prerequisites for computation: Instructions for the computation must be present The instructions must be executed In Java, objects that execute instructions are called Threads Each Thread follows the instructions it is given No object can act except a Thread There can be many Threads executing concurrently How can an ordinary computer execute many Threads “at the same time”? Answer on next slide Fundamentals of Software Development I Lecture 20

Concurrent Threads A computer repeatedly: Called CPU scheduling Round robin First-in, First-Out (FIFO) Shortest job first etc. A computer repeatedly: Picks a Thread Restores the system to the state when the Thread last ran Which statement was it doing? What values were bound to the objects/variables at that time? Runs the Thread for a little while Saves the state of the system The Threads appear to run “at the same time” if the time step is small enough Fundamentals of Software Development I Lecture 20

Runnable: connecting Animate objects and Threads What are they? A Thread is, by definition, an instruction-follower An animate object is, by definition, an object with its own Thread (i.e., its own instruction-follower) What do they promise? The animate object promises to supply instructions The Thread promises to execute them How are they connected? through the Runnable interface (see next slide) Fundamentals of Software Development I Lecture 20

Using the Runnable interface An animate object typically: Implements the Runnable interface Runnable specifies a run method Constructs and starts a Thread In its constructor or soon thereafter Exercise: Write a single expression that constructs a Thread and asks it to start The constructor needs an argument – the object doing the constructing Answer: (new Thread(this)).start() Supplies a method called run: public void run() run often contains a loop that goes for a long time The Thread: executes the animate object’s run method The animate object promises to supply instructions The Thread promises to execute those instructions Fundamentals of Software Development I Lecture 20

Demo: Threads example I’ll show you the Threads project Note: There is a link to it on Angel (under Exercise link in the Schedule page) Note: Timer class: an animate object! Implements Runnable Constructs and starts a new Thread run method Creation of Timers in Threads constructor Interaction of Timers with Panels We’ll use this same example later to demo a GUI (graphical user interface). Ignore details of panels, etc. for now Interaction of Reset button and Timers Independent objects! What does (purposely) NOT work quite right? That is, what needs to be synchronized? Now do the Exercise on Animate Objects and Threads (associated item on today’s schedule) Fundamentals of Software Development I Lecture 20

Threads Threads There can be many Threads executing concurrently Each Thread follows the instructions it is given No object can act except a Thread executes the animate object’s run method There can be many Threads executing concurrently Fundamentals of Software Development I Lecture 20