Slides prepared by Rose Williams, Binghamton University Chapter 20 Java Threads Part II.

Slides:



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

Comp 249 Programming Methodology Chapter 7 - Inheritance – Part A Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia University,
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 1- 1.
ISBN Chapter 1 Preliminaries. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.1-2 Figure 1.1 The von Neumann computer architecture.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 6- 1.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 2- 1.
ISBN Chapter 9 Subprograms. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.9-2 Figure 9.1 The three semantics models of parameter.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 9- 1.
© 2010 Pearson Education, Inc. All rights reserved.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Chapter 15 Geography, Climate, and Natural Resources.
Slides prepared by Rose Williams, Binghamton University Chapter 6 Arrays.
Slides prepared by Rose Williams, Binghamton University Chapter 13 Interfaces and Inner Classes.
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 I.
Slides prepared by Rose Williams, Binghamton University Chapter 17 Swing I.
Slides prepared by Rose Williams, Binghamton University Chapter 14 Generics and the ArrayList Class.
© 2010 Pearson Education, Inc. All rights reserved.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Slides prepared by Rose Williams, Binghamton University Chapter 7 Inheritance.
Slides prepared by Rose Williams, Binghamton University Chapter 9 Exception Handling.
Chapter 2 Application Layer. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 2-2.
© 2010 Pearson Education, Inc. All rights reserved.
Slides prepared by Rose Williams, Binghamton University Chapter 14 Generics and the ArrayList Class.
Chapter 6 (cont'd) Searching for Guinea Pig B: Case Study in Online Research.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Public class MyThread1 extends Thread { public void start() { } public void run() { System.out.print(“Hello \n”) } public class MyThread2 extends Thread.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Slides prepared by Rose Williams, Binghamton University Chapter 20 Java Never Ends.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Slides prepared by Rose Williams, Binghamton University Chapter 13 Interfaces and Inner Classes.
Chapter 13 Income Inequality. Copyright © 2005 Pearson Addison-Wesley. All rights reserved
Slides prepared by Rose Williams, Binghamton University Chapter 18 Applets.
Slides prepared by Rose Williams, Binghamton University Chapter 5 Defining Classes II.
Slides prepared by Rose Williams, Binghamton University Chapter 5 Defining Classes II.
Copyright © 2005 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Chapter 1 The Facts to Be Explained. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 1-2.
Chapter 1 Computer Networks and the Internet. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 1-2.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Slides prepared by Rose Williams, Binghamton University ICS201 Lectures 18 : Threads King Fahd University of Petroleum & Minerals College of Computer Science.
Chapter 6 Wireless and Mobile Networks. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 6-2.
Chapter 3 Transport Layer. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 3-2.
Chapter 6 Human Capital. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 6-2.
Chapter 19 Java Never Ends Slides prepared by Rose Williams, Binghamton University Kenrick Mock University of Alaska Anchorage Copyright © 2008 Pearson.
Slides prepared by Rose Williams, Binghamton University Chapter 11 Recursion.
Chapter 8 The Role of Technology in Growth. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 8-2.
Slides prepared by Rose Williams, Binghamton University Chapter 16 Collections and Iterators.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Slides prepared by Rose Williams, Binghamton University Chapter 11 Recursion.
Slides prepared by Rose Williams, Binghamton University Chapter 6 Arrays.
Slides prepared by Rose Williams, Binghamton University Chapter 16 Collections and Iterators.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Chapter 7 Multimedia Networking. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 7-2.
Chapter 16 Resources and the Environment at the Global Level.
Slides prepared by Rose Williams, Binghamton University Chapter 13 Interfaces and Inner Classes.
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.
Comp 249 Programming Methodology Chapter 8 - Polymorphism Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia University, Montreal,
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Chapter 4 Applications of the Derivative.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1 Functions.
Chapter 14 Generics and the ArrayList Class Slides prepared by Rose Williams, Binghamton University Copyright © 2008 Pearson Addison-Wesley. All rights.
Parallel Processing (CS526) Spring 2012(Week 8).  Shared Memory Architecture  Shared Memory Programming & PLs  Java Threads  Preparing the Environment.
Chapter 10 Introduction to File I/O Section 10.1 Slides prepared by Rose Williams, Binghamton University Kenrick Mock, University of Alaska Anchorage.
Slides prepared by Rose Williams, Binghamton University Chapter 16 Collections and Iterators.
Slides prepared by Rose Williams, Binghamton University Chapter 20 Java Never Ends.
Slides prepared by Rose Williams, Binghamton University Chapter 19 Swing II.
Chapter 19 Java Never Ends
Chapter 4 Constructors Section 4.4
Information Hiding and Encapsulation Section 4.2
Presentation transcript:

Slides prepared by Rose Williams, Binghamton University Chapter 20 Java Threads Part II

© 2006 Pearson Addison-Wesley. All rights reserved20-2 The Runnable Interface Another way to create a thread is to have a class implement the Runnable interface –The Runnable interface has one method heading: public void run(); A class that implements Runnable must still be run from an instance of Thread –This is usually done by passing the Runnable object as an argument to the thread constructor

© 2006 Pearson Addison-Wesley. All rights reserved20-3 The Runnable Interface: Suggested Implementation Outline public class ClassToRun extends SomeClass implements Runnable {... public void run() { // Fill this as if ClassToRun // were derived from Thread }... public void startThread() { Thread theThread = new Thread(this); theThread.start(); }... }

© 2006 Pearson Addison-Wesley. All rights reserved20-4 The Runnable Interface (Part 1 of 5)

© 2006 Pearson Addison-Wesley. All rights reserved20-5 The Runnable Interface (Part 2 of 5)

© 2006 Pearson Addison-Wesley. All rights reserved20-6 The Runnable Interface (Part 3 of 5)

© 2006 Pearson Addison-Wesley. All rights reserved20-7 The Runnable Interface (Part 4 of 5)

© 2006 Pearson Addison-Wesley. All rights reserved20-8 The Runnable Interface (Part 5 of 5)