Top Banner
THREADS Read from SCJP Book Chapter on Threads Uploaded on Wikispaces
12

THREADS Read from SCJP Book Chapter on Threads Uploaded on Wikispaces.

Dec 24, 2015

Download

Documents

Audra Terry
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: THREADS Read from SCJP Book Chapter on Threads Uploaded on Wikispaces.

THREADS

Read from SCJP Book Chapter on Threads Uploaded on Wikispaces

Page 2: THREADS Read from SCJP Book Chapter on Threads Uploaded on Wikispaces.

Typical Scenario• Imagine a stockbroker application with a lot of complex capabilities.

One of its functions is "download last stock option prices," another is "check prices for warnings," and a third time-consuming operation is "analyze historical data for company XYZ.“

• In a single-threaded runtime environment, these actions execute one after another. The next action can happen only when the previous one is finished. If a historical analysis takes half an hour, and the user selects to perform a download and check afterward, the warning may come too late to, say, buy or sell stock as a result.

• We just imagined the sort of application that cries out for multithreading.

Page 3: THREADS Read from SCJP Book Chapter on Threads Uploaded on Wikispaces.

What are Threads ?

Page 4: THREADS Read from SCJP Book Chapter on Threads Uploaded on Wikispaces.

What are Threads?

Page 5: THREADS Read from SCJP Book Chapter on Threads Uploaded on Wikispaces.

Thread Operations

Page 6: THREADS Read from SCJP Book Chapter on Threads Uploaded on Wikispaces.

Thread Life cycle

Page 7: THREADS Read from SCJP Book Chapter on Threads Uploaded on Wikispaces.

Thread Class

Page 8: THREADS Read from SCJP Book Chapter on Threads Uploaded on Wikispaces.

Using the Runnable Interface

Page 9: THREADS Read from SCJP Book Chapter on Threads Uploaded on Wikispaces.

Creating a Thread

Page 10: THREADS Read from SCJP Book Chapter on Threads Uploaded on Wikispaces.

Example

Page 11: THREADS Read from SCJP Book Chapter on Threads Uploaded on Wikispaces.

Subclassing Thread

Page 12: THREADS Read from SCJP Book Chapter on Threads Uploaded on Wikispaces.

Java.lang.Thread