ข้อมูลจาก : http://www.sun.com/training/catalog/courses/CX-310-035.xml
Section 7: Threads
Write code to define, instantiate and start new threads using both java.lang.Thread and java.lang.Runnable.
Recognize conditions that might prevent a thread from executing.
Write code using synchronized wait, notify and notifyAll to protect against concurrent access problems and to communicate between threads.
Define the interaction among threads and object locks when executing synchronized wait, notify or notifyAll.
Rule
http://www.janeg.ca/scjp/threads/overview.html
- 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
- every Java program has at least one thread which is executed when main() is invoked
- all user-level threads are explicitly constructed and started from the main thread or by a thread originally started from main()
- when the last user thread completes any daemon threads are stopped and the application stops
- a thread's default daemon status is the same as that of thread creating it
- you can check the daemon status using isDaemon()
- you can set the daemon status using setDaemon().
|