Java Threads Part II - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

Java Threads Part II

Description:

Java Threads Part II The Runnable Interface Another way to create a thread is to have a class implement the Runnable interface The Runnable interface has one method ... – PowerPoint PPT presentation

Number of Views:119
Avg rating:3.0/5.0
Slides: 10
Provided by: Dr23852
Category:
Tags: java | part | threads

less

Transcript and Presenter's Notes

Title: Java Threads Part II


1
Java ThreadsPart 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 (Contd)
7
The Runnable Interface An Example (Contd)
8
The Runnable Interface An Example (Contd)
9
The Runnable Interface An Example (Contd)
Write a Comment
User Comments (0)
About PowerShow.com