Instructore: Tasneem Darwish1 University of Palestine Faculty of Applied Engineering and Urban Planning Software Engineering Department Concurrent and.

Slides:



Advertisements
Similar presentations
Practice Session 7 Synchronization Liveness Deadlock Starvation Livelock Guarded Methods Model Thread Timing Busy Wait Sleep and Check Wait and Notify.
Advertisements

Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Java How to Program, 9/e CET 3640 Professor: Dr. José M. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
Slides for Chapter 6: Operating System support From Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edition 3, © Addison-Wesley.
© Andy Wellings, 2004 Roadmap  Introduction  Concurrent Programming  Communication and Synchronization  Completing the Java Model  Overview of the.
Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.
3.5 Interprocess Communication Many operating systems provide mechanisms for interprocess communication (IPC) –Processes must communicate with one another.
3.5 Interprocess Communication
Chapter 11 Operating Systems
 2004 Deitel & Associates, Inc. All rights reserved. Chapter 4 – Thread Concepts Outline 4.1 Introduction 4.2Definition of Thread 4.3Motivation for Threads.
Multithreading in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Multithreading in Java Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
© Andy Wellings, 2004 Roadmap  Introduction  Concurrent Programming  Communication and Synchronization  Completing the Java Model  Overview of the.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Multithreaded Programming.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 4: Threads Overview Multithreading Models Threading Issues.
Java How to Program, 9/e CET 3640 Professor: Dr. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
14.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 4: Threads.
Chapter 3 Operating Systems Introduction to CS 1 st Semester, 2015 Sanghyun Park.
Instructore: Tasneem Darwish1 University of Palestine Faculty of Applied Engineering and Urban Planning Software Engineering Department Concurrent and.
Collage of Information Technology University of Palestine Advanced programming MultiThreading 1.
Java Programming: Advanced Topics
CGS 3763 Operating Systems Concepts Spring 2013 Dan C. Marinescu Office: HEC 304 Office hours: M-Wd 11: :30 AM.
Threads. Overview Problem Multiple tasks for computer Draw & display images on screen Check keyboard & mouse input Send & receive data on network Read.
Threads in Java. History  Process is a program in execution  Has stack/heap memory  Has a program counter  Multiuser operating systems since the sixties.
Multithreading in Java Project of COCS 513 By Wei Li December, 2000.
Instructore: Tasneem Darwish1 University of Palestine Faculty of Applied Engineering and Urban Planning Software Engineering Department Concurrent and.
Java Threads Representation and Management of Data on the Internet.
111 © 2002, Cisco Systems, Inc. All rights reserved.
 2004 Deitel & Associates, Inc. All rights reserved. 1 Chapter 4 – Thread Concepts Outline 4.1 Introduction 4.2Definition of Thread 4.3Motivation for.
Enhancements to Java for Real Time Systems Theresa Dsena CSE Fall 2006 Prof. Ganesan.
CE Operating Systems Lecture 11 Windows – Object manager and process management.
Instructor: Tasneem Darwish1 University of Palestine Faculty of Applied Engineering and Urban Planning Software Engineering Department Object Oriented.
A Guide to Advanced Java Faculty:Nguyen Ngoc Tu. Concurrent programming in Java How to make all things run-able?
Multithreading in Java Sameer Singh Chauhan Lecturer, I. T. Dept., SVIT, Vasad.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Introduction to Threads Session 01 Java Simplified / Session 14 / 2 of 28 Objectives Define a thread Define multithreading List benefits of multithreading.
Scis.regis.edu ● CS-434: Object-Oriented Programming Using Java Week 8 Dr. Jesús Borrego Adjunct Faculty Regis University 1.
Threads Doing Several Things at Once. Threads n What are Threads? n Two Ways to Obtain a New Thread n The Lifecycle of a Thread n Four Kinds of Thread.
15.1 Threads and Multi- threading Understanding threads and multi-threading In general, modern computers perform one task at a time It is often.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
13-1 Chapter 13 Concurrency Topics Introduction Introduction to Subprogram-Level Concurrency Semaphores Monitors Message Passing Java Threads C# Threads.
From Coulouris, Dollimore, Kindberg and Blair Distributed Systems: Concepts and Design Edition 5, © Addison-Wesley 2012 Slides for Chapter 7: Operating.
Threads in Java Threads Introduction: After completing this chapter, you will be able to code your own thread, control them efficiently without.
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 2: The Linux System Part 3.
Multithreading & Synchronized Algoritma Pemrograman 3 Sistem Komputer – S1 Universitas Gunadarma 1.
Multithreading. Multitasking The multitasking is the ability of single processor to perform more than one operation at the same time Once systems allowed.
© Andy Wellings, 2004 Thread Priorities I  Although priorities can be given to Java threads, they are only used as a guide to the underlying scheduler.
1 Threads in Java Jingdi Wang. 2 Introduction A thread is a single sequence of execution within a program Multithreading involves multiple threads of.
Chapter 4 – Thread Concepts
Threads in Java Jaanus Pöial, PhD Tallinn, Estonia.
OPERATING SYSTEM CONCEPT AND PRACTISE
Processes and threads.
Process Management Process Concept Why only the global variables?
Chapter 4 – Thread Concepts
Multithreaded Programming in Java
Lecture 21 Concurrency Introduction
Threads CSSE 332 Operating Systems Rose-Hulman Institute of Technology
Definitions Concurrent program – Program that executes multiple instructions at the same time. Process – An executing program (the running JVM for Java.
Chapter 4: Threads.
Modified by H. Schulzrinne 02/15/10 Chapter 4: Threads.
Slides for Chapter 6: Operating System support
Multithreading.
Chapter 4: Threads.
Multithreading.
Chapter 4: Threads.
Chapter 4: Threads.
- When you approach operating system concepts there might be several confusing terms that may look similar but in fact refer to different concepts:  multiprogramming, multiprocessing, multitasking,
NETWORK PROGRAMMING CNET 441
Chapter 4: Threads.
CMSC 202 Threads.
Presentation transcript:

Instructore: Tasneem Darwish1 University of Palestine Faculty of Applied Engineering and Urban Planning Software Engineering Department Concurrent and Real Time programming Completing the Java concurrency model

Instructore: Tasneem Darwish2 Outlines  Thread Priorities and Thread Scheduling  Delaying Threads  Thread Groups  Java event handling  The Process and Runtime Classes  Thread-related Exceptions  Strengths and Limitations of the Java Concurrency Model

Instructore: Tasneem Darwish3 Thread Priorities and Thread Scheduling  Although priorities can be given to Java threads, they are only used as a guide to the underlying scheduler when allocating resources

Instructore: Tasneem Darwish4 Thread Priorities and Thread Scheduling  Java allows a thread's priority to be queried and set via the getPriority and setPriority methods.  By default, a thread has the same priority as its parent.  If the programmer has not allocated a priority to any thread, then all threads are given the NORM_PRIORITY  the Java thread that executes the main method runs with a NORM_PRIORITY

Instructore: Tasneem Darwish5 Thread Priorities and Thread Scheduling  From a real-time perspective, Java's scheduling and priority models are weak; in particular: 1.no guarantee is given that the highest priority runnable thread is always executing. 2.equal priority threads may or may not be time sliced; and 3.different Java priorities may be mapped to the same operating system priority.  Strengthening the scheduling and priority models is a key aim of the RTSJ (Chapter 10).

Instructore: Tasneem Darwish6 Delaying Threads  A relative delay allows a thread to wait for a future time  It can be implemented by using one of the two sleep static methods (defined in the Thread class).  Sleep only guarantees that the thread is released (made executable) after the period has expired  Once the thread has been made runnable, it will then have to wait to be scheduled for execution.  The length of the waiting time will depend on the other runnable threads in the system and their relative priorities

Instructore: Tasneem Darwish7 Delaying Threads  A relative delay allows a thread to wait for a future time  Java's sleep mechanisms support relative delays, but there is no support for an absolute delay.  Absolute delay is to ask the JVM to delay a thread until 2 p.m. on January 31, 2010 (for example).

Instructore: Tasneem Darwish8 Delaying Threads A delay example using sleep  consider a city's traffic light control system.  In the morning "rush hour", say between 7 and 10 a.m., the controllers need to give more time to traffic entering the city centre than to traffic leaving the city centre.  Between the 4 and 7 p.m. "rush hour", the situation is reversed.

Instructore: Tasneem Darwish9 Delaying Threads  Suppose that the following class contains the appropriate duration values:

Instructore: Tasneem Darwish10 Delaying Threads

Instructore: Tasneem Darwish11 Delaying Threads

Instructore: Tasneem Darwish12 Delaying Threads  There are two problems with this approach: 1. no attempt has been made to take into account the time taken to execute the setInboundTimes and setOutboundTimes method calls; 2.The thread may be preempted between finishing the calls to set the durations and the call to the next sleep method.  Support for absolute delays is another key extension provided by the RTSJ (Chapter 7).

Instructore: Tasneem Darwish13 Delaying Threads  a thread usually wait for an arbitrarily long period of time within a synchronized method for an associated notify  there are occasions when the absence of the notify, within a specified period of time, requires that the thread take some alternative action  This is achieved by using the wait method with a specified timeout

Instructore: Tasneem Darwish14 Delaying Threads  the timeout is a relative time  it is not possible to know for certain if the thread has been woken by the timeout expiring or by a notify

Instructore: Tasneem Darwish15 Thread groups  Thread groups allow collections of threads to be grouped together and manipulated as a group rather than as individuals.  Thread groups also provide a means of restricting who does what to which thread.  Every thread in Java is a member of a thread group.  There is a default group associated with the main program, all created threads are placed in this group (by default).  ThreadGroup is the class which supports the thread groups in Java

Instructore: Tasneem Darwish16 Thread groups  When a thread creates a new thread group, it does so from within a thread group.  the new thread group is a child of the current thread group unless a different thread group is passed as a parameter to the constructor.  Using the constructor methods in the ThreadGroup class allows hierarchies of thread groups to be created.  Requests to destroy a thread group will be applied to all threads in the group.

Instructore: Tasneem Darwish17 Thread groups  Setting the maximum priority of a thread group will cause the setPriority method in the Thread class to silently truncate the priorities if they are above the maximum value for the group.

Instructore: Tasneem Darwish18 Java event handling  In Java, threads are the entities that are scheduled by the virtual machine  there are entities scheduled for execution and have an imposed ordering.  User-interface events are good examples for entities that have imposed ordering.  the events are executed by a single thread that imposes the required ordering.  The classes Timer and TimerTask are used for this style of programming.

Instructore: Tasneem Darwish19 Java event handling  Timer object is an execution engine  The Timer accepts requests to schedule tasks for execution  After scheduling the Timer executes these tasks sequentially in an order determined by parameters passed with the schedule request.  A task is an instance of any subclass of the TimerTask

Instructore: Tasneem Darwish20 The process and runtime classes  Java virtual machine executes under control of an operating system.  all modern operating systems support the concept of a process  Java allows the programmer to create and interact with other processes under that host operating system.  this interaction is heavily dependent on the actual host (the O.S) and consequently use of the facilities might reduce the portability of the Java program.

Instructore: Tasneem Darwish21 The process and runtime classes  Java defines two classes to aid interaction with other processes: 1.the java.lang.Process class 2.the java.lang.Runtime class.