java_multithread_programming

java_multithread_programming - IEG 4180 Network Software...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
IEG 4180 IEG 4180 Network Software Design and Programming Network Software Design and Programming Java Java Multithread Multithread Programming Programming
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
IEG4180: Network Software Design and Programming - Java Multithread Programming 2 Copyright Jack Y. B. Lee All Rights Reserved Contents • 1. Introduction • 2. Java Thread APIs • 3. Creating a New Thread • 4. Thread Scheduling • 5. Thread Synchronization • 6. Thread Coordination • 7. Swing and Multithreading • References
Background image of page 2
IEG4180: Network Software Design and Programming - Java Multithread Programming 3 Copyright Jack Y. B. Lee All Rights Reserved 1. Introduction • Thread Support ± Java supports multithreading at the language/JVM level. ± Any platform supporting Java supports multithreading. • Implementations Java Virtual Machine Java Multithread Application Java Thread Classes Java Virtual Machine Java Multithread Application Operating System Native Thread API (e.g., POSIX Pthreads, Win32 threads) Java Thread Classes Internal Implementation of Threads (green threads) JVM-Implemented Threads Using Native Threads
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
IEG4180: Network Software Design and Programming - Java Multithread Programming 4 Copyright Jack Y. B. Lee All Rights Reserved 2. Java Thread APIs • Class/Interface ± A Thread class for sub-classing threaded-classes; ± A Runnable interface to work around single-inheritance; • Thread Synchronization ± The synchronized keyword for mutual exclusion; ± Special methods ( wait() , notify() , etc.) of the Object class for threads coordination; • Thread Management ± A ThreadGroup class for managing threads in groups; ± A ThreadLocal class for implementing thread-local storage.
Background image of page 4
IEG4180: Network Software Design and Programming - Java Multithread Programming 5 Copyright Jack Y. B. Lee All Rights Reserved 3. Creating a New Thread • Method 1: Subclassing the Thread Class ± Step 1 - Subclass from the Thread class ± Step 2 - Create the new thread class ThreadSend extends Thread { public void run( ) { // … } } The new thread will start execution from the run() method. Thread terminates when returned from run() . ThreadSend sender = new ThreadSend(); // Create the thread object sender. start() ; // Create the new thread The start() method is inherited from class Thread . This call start the new thread’s execution from the run() method.
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
IEG4180: Network Software Design and Programming - Java Multithread Programming 6 Copyright Jack Y. B. Lee All Rights Reserved 3. Creating a New Thread • Method 2: Implementing the Runnable Interface ± Step 1 - Implements the Runnable interface ± Step 2 - Start the new thread via a Thread object class ThreadSend implements Runnable { public void run( ) { // … } } The new thread will start execution from the run() method. Thread terminates when returned from
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 29

java_multithread_programming - IEG 4180 Network Software...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online