Presentation is loading. Please wait.

Presentation is loading. Please wait.

Java Threads Part II. Lecture Objectives To understand the concepts of multithreading in Java To be able to develop simple multithreaded applications.

Similar presentations


Presentation on theme: "Java Threads Part II. Lecture Objectives To understand the concepts of multithreading in Java To be able to develop simple multithreaded applications."— Presentation transcript:

1 Java Threads Part II

2 Lecture Objectives To understand the concepts of multithreading in Java To be able to develop simple multithreaded applications in Java

3 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

4 The Runnable Interface: An 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.run(); }... }

5 The Runnable Interface: An Example

6 The Runnable Interface: An Example (Cont’d)

7

8

9


Download ppt "Java Threads Part II. Lecture Objectives To understand the concepts of multithreading in Java To be able to develop simple multithreaded applications."

Similar presentations


Ads by Google