1 Software Construction and Evolution - CSSE 375 Exception Handling – Chaining & Threading Steve Chenoweth Office: Moench Room F220 Phone: (812) 877-8974.

Slides:



Advertisements
Similar presentations
02/05/2008CSCI 315 Operating Systems Design1 Java Threads Notice: The slides for this lecture have been largely based on those accompanying an earlier.
Advertisements

Algorithm Programming Concurrent Programming in Java Bar-Ilan University תשס"ח Moshe Fresko.
G52CON: Concepts of Concurrency Lecture 2 Processes & Threads Chris Greenhalgh School of Computer Science
Thread Control methods The thread class contains the methods for controlling threads Thread() create default thread Thread(target: runnable ) creates new.
02/05/2007CSCI 315 Operating Systems Design1 Java Threads Notice: The slides for this lecture have been largely based on those accompanying the textbook.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L19 (Chapter 24) Multithreading.
CSE S. Tanimoto Java Threads 1 Java Threads (Outline) Motivation The class Thread Example program: ThreadRace The Runnable interface Example: Clock.
CS220 Software Development Lecture: Multi-threading A. O’Riordan, 2009.
Thread Examples. Runnable Interface Runnable defines only one abstract method; Public void run(); Thread also implements Runnable interface. Why does.
22-Jun-15 Threads and Multithreading. 2 Multiprocessing Modern operating systems are multiprocessing Appear to do more than one thing at a time Three.
02/01/2007CSCI 315 Operating Systems Design1 Java Threads Notice: The slides for this lecture have been largely based on those accompanying the textbook.
Synchronization in Java Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
02/02/2004CSCI 315 Operating Systems Design1 Java Threads Notice: The slides for this lecture have been largely based on those accompanying the textbook.
Java ThreadsGraphics Programming Graphics Programming: Java Threads.
Threads II. Review A thread is a single flow of control through a program Java is multithreaded—several threads may be executing “simultaneously” If you.
50.003: Elements of Software Construction Week 5 Basics of Threads.
Parallel Processing (CS526) Spring 2012(Week 8).  Thread Status.  Synchronization in Shared Memory Programming(Java threads ) ◦ Locks ◦ Barriars.
1 CSCD 330 Network Programming Lecture 13 More Client-Server Programming Sometime in 2014 Reading: References at end of Lecture.
A Bridge to Your First Computer Science Course Prof. H.E. Dunsmore Concurrent Programming Threads Synchronization.
Chapter 15 Multithreading F Threads Concept  Creating Threads by Extending the Thread class  Creating Threads by Implementing the Runnable Interface.
University of Sunderland Java Threading, Mutex and Synchronisation Lecture 02 COMM86 Concurrent and Distributed Software Systems.
1 Software Construction and Evolution - CSSE 375 Exception Handling – Logging & Special Situations Steve Chenoweth Office: Moench Room F220 Phone: (812)
1 CSCE3193: Programming Paradigms Nilanjan Banerjee Programming Paradigms University of Arkansas Fayetteville, AR
Quick overview of threads in Java Babak Esfandiari (extracted from Qusay Mahmoud’s slides)
REVIEW On Friday we explored Client-Server Applications with Sockets. Servers must create a ServerSocket object on a specific Port #. They then can wait.
Today’s Agenda  Quick Review  Finish Java Threads  The CS Problem Advanced Topics in Software Engineering 1.
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.
1 Software Construction and Evolution - CSSE 375 Exception Handling - Principles Steve Chenoweth, RHIT Above – Exception handling on the ENIAC. From
Threads in Java. Processes and Threads Processes –A process has a self-contained execution environment. –Has complete set of runtime resources including.
1 Web Based Programming Section 8 James King 12 August 2003.
1 (Worker Queues) cs What is a Thread Pool? A collection of threads that are created once (e.g. when a server starts) That is, no need to create.
Li Tak Sing COMPS311F. Case study: consumers and producers A fixed size buffer which can hold at most certain integers. A number of producers which generate.
Threading Eriq Muhammad Adams J
Synchronized and Monitors. synchronized is a Java keyword to denote a block of code which must be executed atomically (uninterrupted). It can be applied.
JAVA COURSE LESSON2 BY OMPUTER ENGINEEING ASSOCIATION.
Multithreading in Java Sameer Singh Chauhan Lecturer, I. T. Dept., SVIT, Vasad.
Introduction to Threads Session 01 Java Simplified / Session 14 / 2 of 28 Objectives Define a thread Define multithreading List benefits of 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
Advanced Concurrency Topics Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
Threads II IS Outline  Quiz  Thread review  Stopping a thread  java.util.Timer  Swing threads javax.swing.Timer  ProgressMonitor.
Java Thread and Memory Model
Java the UML Way version Only to be used in connection with the book "Java the UML Way", by Else Lervik and.
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.
Concurrent Computing CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
Multi-Threading in Java
Multithreaded programming  Java provides built-in support for multithreaded programming. A multithreaded program contains two or more parts that can run.
Multithreading. Multithreaded Programming A multithreaded program contains two or more parts that can run concurrently. Each part of such a program is.
Parallel Processing (CS526) Spring 2012(Week 8).  Shared Memory Architecture  Shared Memory Programming & PLs  Java Threads  Preparing the Environment.
Comunication&Synchronization threads 1 Programación Concurrente Benemérita Universidad Autónoma de Puebla Facultad de Ciencias de la Computación Comunicación.
Threads in Java Threads Introduction: After completing this chapter, you will be able to code your own thread, control them efficiently without.
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.
Multithreaded applets
Multithreading / Concurrency
Chapter 13: Multithreading
Multi Threading.
Multithreading.
Chapter 19 Java Never Ends
Threads Chate Patanothai.
© 2002, Mike Murach & Associates, Inc.
Java Threads (Outline)
Java Threads (Outline)
Chapter 15 Multithreading
Threads in Java James Brucker.
Threads and Multithreading
Software Engineering and Architecture
Java Chapter 3 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

1 Software Construction and Evolution - CSSE 375 Exception Handling – Chaining & Threading Steve Chenoweth Office: Moench Room F220 Phone: (812) hulman.edu Below – Chaining is a concept at the heart of several different areas of CS. Below, we see a Rule-based AI system, where chaining the rules is a key to giving the system generality and power. From a description of JBoss, at US/JBoss_Enterprise_BRMS_Platform/5/html- single/JBoss_Rules_5_Reference_Guide/index. html US/JBoss_Enterprise_BRMS_Platform/5/html- single/JBoss_Rules_5_Reference_Guide/index. html

2 Exception Handling - Chaining In Java, chaining lets you set up associations between exceptions. This lets you throw a “custom exception” within an exception, explaining what it means – a “root cause” Below – One example of error handling chaining – escalation. Note that, at some point, humans get involved! From 85/extending-the-oracle-bpel- error-hospital-with-custom-java- actions 85/extending-the-oracle-bpel- error-hospital-with-custom-java- actions

3 Java Chaining Example try{ // lots of risky I/O operations! } catch (java.io.IOException rootCause){ throw new ConnectionException(rootCause); } Which requires a constructor like: public class ConnectionException extends java.io.IOException{ public ConnectionException(Throwable cause){ // analyzes the cause } Thus, you can group related exceptions in ways you define. So, here’s an exception routine throwing a more general exception! Q1

4 Exception Handling - Threading Typical issue – – You want to make the GUI multi-task, for efficiency. – So, things finish when you’re in the middle of something else. – What happens if they finish in an error condition? Above – Multithreading in.Net, from

5 Thread Design Use a design tool that shows step-by-step functionality, like: – State chart, or – Sequence diagram Add the possible error situations, and how you’ll deal with those – E.g., at what point does one thread need to check to see if another finished properly? Q2

6 How do threads communicate? Different for different kinds of multi-threaded programs. For producer / consumer systems, for example: – Consumer threads can actively check the state of the producer – Consumer threads can wait for the producer by calling the join method – Producer thread can actively notify the consumers – Producer thread can throw an InterruptedException to notify the consumer threads Let’s talk about this one…

7 Thread exceptions to communicate! How it works – – Producer method calls the interrupt method on the consumer threads – If consumer method’s already running, it can call its method interrupted, which will return true if it’s been the target of an interrupt call. Or, – If the thread was blocked during the call, the producer’s interrupt call will cause an InterruptedException to be thrown for the consumer. Advantages – – Threads can be notified during blocking calls – Easy to use for groups of threads – Immediate notification Q3

8 Example import java.util.*; public class ProducerThread implements Runnable{ private ThreadGroup consumers; private Thread runner; private boolean shutdown; private ArrayList tasks; public ProducerThread(ThreadGroup msgConsumers) { msgConsumers.checkAccess(); consumers = msgConsumers; tasks = new ArrayList(); runner = new Thread(this); runner.start(); } public void shutdown(){ shutdown = true; } public synchronized void addTask(Task t){ if (t != null){ tasks.add(t); } public synchronized Task removeTask(){ Task rtnTask = null; if (!tasks.isEmpty()){ rtnTask = (Task) tasks.remove(0); } private boolean hasTasks(){ return tasks.isEmpty(); } public void run(){ while (!shutdown){ if (hasTasks()){ consumers.interrupt(); } try { Thread.sleep(1000); } catch (InterruptedException exc){ } Code goes here for “what it does when sleep’s interrupted”