120 likes | 236 Vues
In modern stockbroker applications, managing multiple tasks simultaneously is crucial for timely decisions. A typical scenario includes functions like downloading stock options, checking prices for alerts, and analyzing historical data. In a single-threaded environment, these tasks must occur sequentially, leading to delays that can significantly impact trading opportunities. This chapter discusses the concept of threads, their operations, lifecycle, and how to implement them using the Runnable interface and Java's Thread class, showcasing how multithreading enhances performance and user experience.
E N D
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.