THREADS Read from SCJP Book Chapter on Threads Uploaded on Wikispaces.
-
Upload
audra-terry -
Category
Documents
-
view
230 -
download
0
Transcript of THREADS Read from SCJP Book Chapter on Threads Uploaded on Wikispaces.
![Page 1: THREADS Read from SCJP Book Chapter on Threads Uploaded on Wikispaces.](https://reader034.fdocuments.in/reader034/viewer/2022051113/56649dc45503460f94ab7425/html5/thumbnails/1.jpg)
THREADS
Read from SCJP Book Chapter on Threads Uploaded on Wikispaces
![Page 2: THREADS Read from SCJP Book Chapter on Threads Uploaded on Wikispaces.](https://reader034.fdocuments.in/reader034/viewer/2022051113/56649dc45503460f94ab7425/html5/thumbnails/2.jpg)
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.](https://reader034.fdocuments.in/reader034/viewer/2022051113/56649dc45503460f94ab7425/html5/thumbnails/3.jpg)
What are Threads ?
![Page 4: THREADS Read from SCJP Book Chapter on Threads Uploaded on Wikispaces.](https://reader034.fdocuments.in/reader034/viewer/2022051113/56649dc45503460f94ab7425/html5/thumbnails/4.jpg)
What are Threads?
![Page 5: THREADS Read from SCJP Book Chapter on Threads Uploaded on Wikispaces.](https://reader034.fdocuments.in/reader034/viewer/2022051113/56649dc45503460f94ab7425/html5/thumbnails/5.jpg)
Thread Operations
![Page 6: THREADS Read from SCJP Book Chapter on Threads Uploaded on Wikispaces.](https://reader034.fdocuments.in/reader034/viewer/2022051113/56649dc45503460f94ab7425/html5/thumbnails/6.jpg)
Thread Life cycle
![Page 7: THREADS Read from SCJP Book Chapter on Threads Uploaded on Wikispaces.](https://reader034.fdocuments.in/reader034/viewer/2022051113/56649dc45503460f94ab7425/html5/thumbnails/7.jpg)
Thread Class
![Page 8: THREADS Read from SCJP Book Chapter on Threads Uploaded on Wikispaces.](https://reader034.fdocuments.in/reader034/viewer/2022051113/56649dc45503460f94ab7425/html5/thumbnails/8.jpg)
Using the Runnable Interface
![Page 9: THREADS Read from SCJP Book Chapter on Threads Uploaded on Wikispaces.](https://reader034.fdocuments.in/reader034/viewer/2022051113/56649dc45503460f94ab7425/html5/thumbnails/9.jpg)
Creating a Thread
![Page 10: THREADS Read from SCJP Book Chapter on Threads Uploaded on Wikispaces.](https://reader034.fdocuments.in/reader034/viewer/2022051113/56649dc45503460f94ab7425/html5/thumbnails/10.jpg)
Example
![Page 11: THREADS Read from SCJP Book Chapter on Threads Uploaded on Wikispaces.](https://reader034.fdocuments.in/reader034/viewer/2022051113/56649dc45503460f94ab7425/html5/thumbnails/11.jpg)
Subclassing Thread
![Page 12: THREADS Read from SCJP Book Chapter on Threads Uploaded on Wikispaces.](https://reader034.fdocuments.in/reader034/viewer/2022051113/56649dc45503460f94ab7425/html5/thumbnails/12.jpg)
Java.lang.Thread