threads read from scjp book chapter on threads uploaded on wikispaces

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

Upload: audra-terry

Post on 24-Dec-2015

228 views

Category:

Documents


0 download

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