CSE 205 Lecture Notes - Lecture 26: Multiprocessing, Instance Variable, Java Virtual Machine
CSE 205 – Lecture 26 – Threads
• Topics
o Java Threads and Runnables
o Running Threads
o Synchronization
• What is a thread?
o An independent path of execution through program code
o When multiple threads execute byte-code instruction sequences in the same
program
â–Ş Known as multithreading
• Benefits of multithreading
o Multithreaded GUI-based programs
â–Ş remain responsive to users while performing other tasks such as:
• printing a document
• opening a web browser
â–Ş Threaded programs typically finish faster than their non-threaded
counterparts
• Especially true of threads running on a multiprocessor machine,
where each thread has its own processor
• Running Multi-Threads
o On a single processor, multithreading generally occurs by multitasking
â–Ş The processor switches between different threads
o Java supports the creation of programs with concurrent flows of control
o The Java virtual machine (JVM) executes each thread for a short amount of time
and then switches to another thread
• Thread class in Java.lang
o Java accomplishes multithreading through its java.lang.Thread class
o Each Thread object describes a single thread of execution
o The execution occurs in Thread’s run() method