Recitation 12 November 18, 2011.

Slides:



Advertisements
Similar presentations
Unit 141 Threads What is a Thread? Multithreading Creating Threads – Subclassing java.lang.Thread Example 1 Creating Threads – Implementing java.lang.Runnable.
Advertisements

Thread Control methods The thread class contains the methods for controlling threads Thread() create default thread Thread(target: runnable ) creates new.
Java Threads Part II. Lecture Objectives To understand the concepts of multithreading in Java To be able to develop simple multithreaded applications.
Slides for Chapter 6: Operating System support From Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edition 3, © Addison-Wesley.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L19 (Chapter 24) Multithreading.
1Threads What are they? Why are they important? How are they implemented in OSes? How to use threads? (in Java)
Slides prepared by Rose Williams, Binghamton University Chapter 20 Java Threads Part II.
Concurrency…leading up to writing a web crawler. Web crawlers.
CS220 Software Development Lecture: Multi-threading A. O’Riordan, 2009.
Overview Review – what constitutes a thread Creating threads – general Creating threads – Java What happens if synchronization is not used? Assignment.
Java ThreadsGraphics Programming Graphics Programming: Java Threads.
Macro & Function. Function consumes more time When a function is called, the copy of the arguments are passed to the parameters in the function. After.
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.
C OMP 401 A NIMATION L OOPS Instructor: Prasun Dewan.
Lecture 5 : JAVA Thread Programming Courtesy : MIT Prof. Amarasinghe and Dr. Rabbah’s course note.
Multi-Threaded Application CSNB534 Asma Shakil. Overview Software applications employ a strategy called multi- threaded programming to split tasks into.
Java Threads Representation and Management of Data on the Internet.
Dr. R R DOCSIT, Dr BAMU. Basic Java : Multi Threading 2 Objectives of This Session State what is Multithreading. Describe the life cycle of Thread.
111 © 2002, Cisco Systems, Inc. All rights reserved.
CSC 212 Stacks & Queues. Announcement Many programs not compiled before submission  Several could not be compiled  Several others not tested with javadoc.
1 Recitation 8. 2 Outline Goals of this recitation: 1.Learn about loading files 2.Learn about command line arguments 3.Review of Exceptions.
Concurrent Programming and Threads Threads Blocking a User Interface.
Multithreading in Java Sameer Singh Chauhan Lecturer, I. T. Dept., SVIT, Vasad.
Introduction to Threads Session 01 Java Simplified / Session 14 / 2 of 28 Objectives Define a thread Define multithreading List benefits of multithreading.
Multithreading in JAVA
Java Thread and Memory Model
Concurrency Control 1 Fall 2014 CS7020: Game Design and Development.
SurfaceView.
Multi-Threading in Java
C OMP 401 U SER -I NTERFACE VS. M AIN T HREADS Instructor: Prasun Dewan.
Parallel Processing (CS526) Spring 2012(Week 8).  Shared Memory Architecture  Shared Memory Programming & PLs  Java Threads  Preparing the Environment.
Chapter11 Concurrent. 集美大学 计算机工程学院 Java 程序设计 年 第二版 Concurrent ●Computer users take it for granted that their systems can do more than one thing.
1 OS Review Processes and Threads Chi Zhang
From Coulouris, Dollimore, Kindberg and Blair Distributed Systems: Concepts and Design Edition 5, © Addison-Wesley 2012 Slides for Chapter 7: Operating.
1 Java Programming Java Programming II Concurrent Programming: Threads ( I)
Threads b A thread is a flow of control in a program. b The Java Virtual Machine allows an application to have multiple threads of execution running concurrently.
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.
Recitation 5 September 23, As you come in...  Please sit next to someone you will collaborate with for today’s recitation.  Choose someone with.
Concurrency in Java MD. ANISUR RAHMAN. slide 2 Concurrency  Multiprogramming  Single processor runs several programs at the same time  Each program.
Concurrent Programming in Java Based on Notes by J. Johns (based on Java in a Nutshell, Learning Java) Also Java Tutorial, Concurrent Programming in Java.
Java Thread Programming
Threads.
Multithreaded applets
Multithreading / Concurrency
Chapter 13: Multithreading
Multi Threading.
Java Multithreading.
Java Programming Language
Chapter 2 Processes and Threads Today 2.1 Processes 2.2 Threads
Chapter 5: Threads Overview Multithreading Models Threading Issues
Exceptions, Interfaces & Generics
Threads Chate Patanothai.
Concurring Concurrently
Recitation 4 Comp
Slides for Chapter 6: Operating System support
Multithreading.
Multithreading 2 Lec 24.
Java Based Techhnology
Java Threads (Outline)
Recitation 7 October 7, 2011.
Java Threads (Outline)
21 Threads.
Chapter 15 Multithreading
Multithreading in java.
Threads.
Corresponds with Chapter 5
CMSC 202 Threads.
Mobile Computing With Android ACST 4550 Android Animation
Java Chapter 3 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

Recitation 12 November 18, 2011

Today’s Goals: Use Threads to animate changes.

Creating a thread } Creates a new Command Creates a new Java thread public void animateFromOrigin() { Runnable animateCommand = new AnimationCommand(…); Thread thread = new Thread(animateCommand); thread.setName(“Shuttle Animation”); thread.start(); } Invokes the run method on the command object passed to constructor.

Pausing a thread void sleep(int pauseTime) { try { // OS suspends program for pauseTime Thread.sleep(pauseTime); } catch (Exception e) { // program may be forcibly interrupted while sleeping e.printStackTrace(); }; }

java.lang.Runnable Interface Command Object run () package java.lang; public interface Runnable { public void run(); }

Runnable Implementation public class AShuttleAnimationCommand implements Runnable{ Shuttle shuttle; int animationStep, animationPauseTime; public AShuttleAnimationCommand (Shuttle shuttle, int step, int pause) { this.shuttle = shuttle; animationStep = step; animationPauseTime = pause; } public void run() { shuttle.animateFromOrigin(animationStep,animationPauseTime); Note: Will likely need to specify additional parameters (e.g. where to move to!) Parameters Target Object

Recitation Specification Goal: Animate the changes to a Triangle’s x and y position. Tasks: Implement animateSetX/Y methods in CartesianLine.java Implement run() in both ASetXCommand and ASetYCommand Bonus: Animate push and pop onto shape stack, using code from Recitation 11

Setup and Submission Work with a single partner! Please follow the instructions on the course website to set up and submit your projects! Set up your project: http://www.cs.unc.edu/~dewan/comp114/f10/Recitations/makeproject/ Submit an assignment: http://www.cs.unc.edu/~dewan/comp114/f10/Recitations/submit/ Work with a single partner!