Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 More on Thread API.

Slides:



Advertisements
Similar presentations
Concurrent Programming Abstraction & Java Threads
Advertisements

Ade Azurat, Advanced Programming 2004 (Based on LYS Stefanus’s slides) Advanced Programming 2004, Based on LYS Stefanus’s slides Slide 2.1 Multithreading.
1 CSC321 §2 Concurrent Programming Abstraction & Java Threads Section 2 Concurrent Programming Abstraction & Java Threads.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 5 Multithreading and.
Java How to Program, 9/e CET 3640 Professor: Dr. José M. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
1 L49 Multithreading (1). 2 OBJECTIVES  What threads are and why they are useful.  How threads enable you to manage concurrent activities.  The life.
Thread Control methods The thread class contains the methods for controlling threads Thread() create default thread Thread(target: runnable ) creates new.
Slides for Chapter 6: Operating System support From Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edition 3, © Addison-Wesley.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L19 (Chapter 24) Multithreading.
CS220 Software Development Lecture: Multi-threading A. O’Riordan, 2009.
Ceng Operating Systems Chapter 2.1 : Processes Process concept Process scheduling Interprocess communication Deadlocks Threads.
Java How to Program, 9/e CET 3640 Professor: Dr. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
Parallel Processing (CS526) Spring 2012(Week 8).  Thread Status.  Synchronization in Shared Memory Programming(Java threads ) ◦ Locks ◦ Barriars.
Collage of Information Technology University of Palestine Advanced programming MultiThreading 1.
Internet Software Development More stuff on Threads Paul Krause.
Java Programming: Advanced Topics
1 Java Threads Instructor: Mainak Chaudhuri
Threads. Overview Problem Multiple tasks for computer Draw & display images on screen Check keyboard & mouse input Send & receive data on network Read.
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 Inter-Thread communication State dependency: Guarded Methods.
Quick overview of threads in Java Babak Esfandiari (extracted from Qusay Mahmoud’s slides)
Today’s Agenda  Quick Review  Finish Java Threads  The CS Problem Advanced Topics in Software Engineering 1.
1 Tutorial: CSI 3310 Dewan Tanvir Ahmed SITE, UofO.
Java Threads Representation and Management of Data on the Internet.
Dr. R R DOCSIT, Dr BAMU. Basic Java : Multi Threading 2 Objectives of This Session State what is Multithreading. Describe the life cycle of Thread.
111 © 2002, Cisco Systems, Inc. All rights reserved.
Java Threads. What is a Thread? A thread can be loosely defined as a separate stream of execution that takes place simultaneously with and independently.
1 Chapter 2.1 : Processes Process concept Process concept Process scheduling Process scheduling Interprocess communication Interprocess communication Threads.
Threads.
Introduction to Threads Session 01 Java Simplified / Session 14 / 2 of 28 Objectives Define a thread Define multithreading List benefits of multithreading.
Advanced Programming 2004, based on LY Stefanus’s slides slide 8.1 Multithreading : Thread Scheduling ThreadGroup.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 18 Advanced Java Concepts Threads and Multithreading.
In Java processes are called threads. Additional threads are associated with objects. An application is associated with an initial thread via a static.
Multithreading in JAVA
Object-oriented Programming in Java. © Aptech Ltd. Introduction to Threads/Session 7 2  Introduction to Threads  Creating Threads  Thread States 
Scis.regis.edu ● CS-434: Object-Oriented Programming Using Java Week 8 Dr. Jesús Borrego Adjunct Faculty Regis University 1.
Java 3: Odds & Ends Advanced Programming Techniques.
Multithreading. Multithreaded Programming A multithreaded program contains two or more parts that can run concurrently. Each part of such a program is.
MultiThreading Sangeetha Parthasarathy 07/10/2001.
Threads in Java Threads Introduction: After completing this chapter, you will be able to code your own thread, control them efficiently without.
Thread A thread represents an independent module of an application that can be concurrently execution With other modules of the application. MULTITHREADING.
Internet Computing Module II. Threads – Multithreaded programs, thread Priorities and Thread Synchronization.
THREAD MODEL.
Multithreading. Multitasking The multitasking is the ability of single processor to perform more than one operation at the same time Once systems allowed.
Java Threads Lilin Zhong. Java Threads 1. New threads 2. Threads in the running state 3. Sleeping threads and interruptions 4. Concurrent access problems.
Threads b A thread is a flow of control in a program. b The Java Virtual Machine allows an application to have multiple threads of execution running concurrently.
Chapter 13: Multithreading The Thread class The Thread class The Runnable Interface The Runnable Interface Thread States Thread States Thread Priority.
1 Threads in Java Jingdi Wang. 2 Introduction A thread is a single sequence of execution within a program Multithreading involves multiple threads of.
Concurrent Programming in Java Based on Notes by J. Johns (based on Java in a Nutshell, Learning Java) Also Java Tutorial, Concurrent Programming in Java.
1 Multithreading in Java THETOPPERSWAY.COM. 2 Outline  Multithreading & Thread Introduction  Creating threads  Thread Life Cycle  Threads priorities.
Java Thread Programming
Threads in Java Jaanus Pöial, PhD Tallinn, Estonia.
Multithreading / Concurrency
Multi Threading.
Java Multithreading.
Multithreading.
Applied Operating System Concepts -
Multithreaded Programming in Java
Multithreading in Java
More About Threads.
Threads Chate Patanothai.
Slides for Chapter 6: Operating System support
Multithreading.
Multithreading 2 Lec 24.
Java Based Techhnology
Multithreading.
Multithreaded Programming
21 Threads.
Multithreading in java.
Threads and Multithreading
Java Chapter 3 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 More on Thread API

Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 2 public void interrupt(); Receiving thread is interrupted. public boolean isInterrupted() Tests whether this thread has been interrupted. public static boolean interrupted() Tests whether the current thread has been interrupted. The interrupted status of the thread is cleared by this method. In other words, if this method were to be called twice in succession, the second call would return false (unless the current thread were interrupted again, after the first call had cleared its interrupted status and before the second call had examined it). static void yield() Causes the currently executing thread object to temporarily pause and allow other threads to execute.

Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 3 Deprecated methods: –public final void suspend() –public final void resume() –public final void stop() A thread is considered alive just after the start() method is invoked, until its run() method naturally terminates; if you choose to stop a thread use interrupt(). Read example : BestReplacement.java in hyde/code

Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 4 Deamon threads Used for background supporting tasks, and needed while normal non-deamon threads are running. When the JVM detects that only reamining threads are deamon threads it exits. Used to manage behind-the-scenes processing needed by all other threads. After a thread is created it can be set to deamon with –public void setDeamon(Boolean flag);

Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 5 JVM threads priorities Priority Thread name 5main 8Finalizer (for gc) 10Reference handler 5signal dispatcher 5AWT Windows 6AWT-Event-Queue-0 5SunToolKit.PostEventQueue-0 4Screen updater

Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 6 Assigning priorities Consider the relative priorities of JVM threads to be sure your threads do not overwhelm their operations. By default, when a new thread is created it runs at same priority as the thread that created it. Most threads are created by the main, so are at priority 5. There are times when you want to raise or lower the priority.

Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 7 API Priority public int getPriority() public final void setPriority(int newPriority) Changes the priority of this thread. First the checkAccess method of this thread is called with no arguments. This may result in throwing a SecurityException. Otherwise, the priority of this thread is set to the smaller of the specified newPriority and the maximum permitted priority of the thread's thread group. static int MAX_PRIORITY The maximum priority that a thread can have. static int MIN_PRIORITY The minimum priority that a thread can have. static int NORM_PRIORITY The default priority that is assigned to a thread.

Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 8 Priority Tip When assigning priorities to threads in your app, use the higher priorities only for threads that block frequently (sleep, wait, block on I/O, even yield). CPU intensive calculations should be done with a medium-to-low priority thread to ensure that processor is not hogged. Avoid setting Thread.MAX_PRIORITY unless thread spends nearly all of its time blocked or it is very short-lived.

Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 9 Threads states on a single processor State block InterruptedDescription Runningcurrently running Ready to runwaiting for turn on processor Sleeping X X interrupted will move to ready to run after certain amount of time has elapsed or after being interrupted. Waiting X X will move to ready to run after being notified, after timing out, or after being interrupted. Blocked on I/O X will move to ready to run after I/O condition changes. Blocked on sync X will move to ready to run when lock is acquired.

Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 10 Transition states New tread Ready to run running Sleeping Waiting Blocked on I/O Blocked on Sync start() Chosen by scheduler To run yield() scheduler swaps it out thread blocks unblocks