|
|
Threads - Overview
- on an operating system a running program is known as a process
- a single process can have seperate runnable tasks called threads
- a thread is a single sequential flow of control within a process
- a thread is also referred to as a lightweight process
- with a single-processor CPU, only one thread is executing at any given time
- the CPU quickly switches between active threads giving the illusion that they are all executing at the same time (logical concurrency)
- on multi-processor systems several threads are actually executing at the same time (physical concurrency)
- multi-programming occurs when multiple programs or processes are executed
- multi-threading occurs when concurrency exists amoung threads running in a single process (also referred to as multi-tasking)
- Java provides support for multi-threading as a part of the language
- support centers on the:
- java.lang.Thread class
- java.lang.Runnable interface
- java.lang.Object methods wait(), notify(), and notifyAll
- synchronized keyword
- there are two basic ways to create and run threads
- by subclassing the Thread class
- by implementing the Runnable interface
Also see
Example Code
|