SlideServe
Menu
Préférences
© SlideServe · v2026

Understanding Multithreading: Concepts, Models, and Applications in Operating Systems and Java

zarita avatar
22 diapositives · 418 Views · Sep 15, 2014

Explore the essentials of multithreading in operating systems, covering user and kernel threads, and various multithreading models like many-to-one, one-to-one, and many-to-many. Learn how Solaris and Java implement these concepts, including thread creation through extending the Thread class and implementing the Runnable interface. Discover the benefits of multithreading such as responsiveness, resource sharing, and efficient utilization of multiprocessor architectures. Understand thread management in Java, including states and common practices using examples such as the Producer-Consumer problem.

Understanding Multithreading: Concepts, Models, and Applications in Operating Systems and Java - slide 1
01 / 22Understanding Multithreading: Concepts, Models, and Applications in Operating Systems and Java
1 / 17

Télécharger la présentation

Understanding Multithreading: Concepts, Models, and Applications in Operating Systems and Java
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Module 5: Threads • Benefits • User and Kernel Threads • Multithreading Models • Solaris 2 Threads • Java Threads Applied Operating System Concepts

  2. Benefits • Responsiveness • Resource Sharing • Economy • Utilization of MP Architectures Applied Operating System Concepts

  3. Single and Multithreaded Processes Applied Operating System Concepts

  4. Multithreading Models • Many-to-One • One-to-One • Many-to-Many Applied Operating System Concepts

  5. Many-to-One • Many User-Level Threads Mapped to Single Kernel Thread. • Used on Systems That Do Not Support Kernel Threads. Applied Operating System Concepts

  6. Many-to-one Model Applied Operating System Concepts

  7. One-to-One • Each User-Level Thread Maps to Kernel Thread. • Examples - Windows 95/98/NT - OS/2 Applied Operating System Concepts

  8. One-to-one Model Applied Operating System Concepts

  9. Many-to-many Model Applied Operating System Concepts

  10. Solaris 2 Threads Applied Operating System Concepts

  11. Solaris Process Applied Operating System Concepts

  12. Java Threads • Java Threads May be Created by: • Extending Thread class • Implementing the Runnable interface Applied Operating System Concepts

  13. Extending the Thread Class class Worker1 extends Thread { public void run() { System.out.println(“I am a Worker Thread”); } } Applied Operating System Concepts

  14. Creating the Thread public class First { public static void main(String args[]) { Worker runner = new Worker1(); runner.start(); System.out.println(“I am the main thread”); } } Applied Operating System Concepts

  15. The Runnable Interface public interface Runnable { public abstract void run(); } Applied Operating System Concepts

  16. Implementing the Runnable Interface class Worker2 implements Runnable { public void run() { System.out.println(“I am a Worker Thread”); } } Applied Operating System Concepts

  17. Creating the Thread public class Second { public static void main(String args[]) { Runnable runner = new Worker2(); Thread thrd = new Thread(runner); thrd.start(); System.out.println(“I am the main thread”); } } Applied Operating System Concepts

  18. Java Thread Management • suspend() – suspends execution of the currently running thread. • sleep() – puts the currently running thread to sleep for a specified amount of time. • resume() – resumes execution of a suspended thread. • stop() – stops execution of a thread. Applied Operating System Concepts

  19. Java Thread States Applied Operating System Concepts

  20. Producer Consumer Problem public class Server { public Server() { MessageQueue mailBox = new MessageQueue(); Producer producerThread = new Producer(mailBox); Consumer consumerThread = new Consumer(mailBox); producerThread.start(); consumerThread.start(); } public static void main(String args[]) { Server server = new Server(); } } Applied Operating System Concepts

  21. Producer Thread class Producer extends Thread { public Producer(MessageQueue m) { mbox = m; } public void run() { while (true) { // produce an item & enter it into the buffer Date message = new Date(); mbox.send(message); } } private MessageQueue mbox; } Applied Operating System Concepts

  22. Consumer Thread class Consumer extends Thread { public Consumer(MessageQueue m) { mbox = m; } public void run() { while (true) { Date message = (Date)mbox.receive(); if (message != null) // consume the message } } private MessageQueue mbox; } Applied Operating System Concepts