CSC Multiprocessor Programming, Spring, 2012

Slides:



Advertisements
Similar presentations
Generalized Requests. The current definition They are defined in MPI 2 under the hood of the chapter 8 (External Interfaces) Page 166 line 16 The objective.
Advertisements

How to Build Multi- threaded Applications in.NET Mazen S. Alzogbi Technology Specialist Microsoft Corporation.
Concurrency (p2) synchronized (this) { doLecture(part2); } synchronized (this) { doLecture(part2); }
CSCC69: Operating Systems
Chapter 6: Process Synchronization
CSC Multiprocessor Programming, Spring, 2011 Outline for Chapter 6 – Task Execution Dr. Dale E. Parson, week 7.
Object Oriented Programming with Java (150704).   Applet  AWT (Abstract Window Toolkit)  Japplet  Swing Types of Applet.
OOP Design Patterns Chapters Design Patterns The main idea behind design patterns is to extract the high level interactions between objects and.
 2007 Pearson Education, Inc. All rights reserved. 1 Ch23 Multithreading: OBJECTIVES In this chapter you will learn:  What threads are and why they are.
490dp Synchronous vs. Asynchronous Invocation Robert Grimm.
CS220 Software Development Lecture: Multi-threading A. O’Riordan, 2009.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L20 (Chapter 24) Multithreading.
Process Management. Processes Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication.
Chapter 6 Operating System Support. This chapter describes how middleware is supported by the operating system facilities at the nodes of a distributed.
BI-SW Training day Outline What is the EDT? Why should I care about it? How do I treat GUI objects properly? SwingWorker and its advantages.
Java Threads 11 Threading and Concurrent Programming in Java Introduction and Definitions D.W. Denbo Introduction and Definitions D.W. Denbo.
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.
1 GUI programming with threads. 2 Threads and Swing Swing is not generally thread-safe: most methods are not synchronized –correct synchronization is.
OPERATING SYSTEM SUPPORT DISTRIBUTED SYSTEMS CHAPTER 6 Lawrence Heyman July 8, 2002.
Concurrent Programming and Threads Threads Blocking a User Interface.
Keeping your Swing Applications Responsive using FoxTrot and Friends Rob Ratcliff.
Chapter 2 Processes and Threads Introduction 2.2 Processes A Process is the execution of a Program More specifically… – A process is a program.
CSC Multiprocessor Programming, Spring, 2012 Chapter 7 – Cancellation & Shutdown Dr. Dale E. Parson, week 9-10.
Lecture 5: Threads process as a unit of scheduling and a unit of resource allocation processes vs. threads what to program with threads why use threads.
Before class… 下禮拜一交 Proposal – 至多四人一組, 同組同分 – 請勿超過一張 A4 評分標準 創意 技術難度 實用性 User-defined 完整性.
CSC Multiprocessor Programming, Spring, 2012 Chapter 11 – Performance and Scalability Dr. Dale E. Parson, week 12.
(1) Introduction to Java GUIs Philip Johnson Collaborative Software Development Laboratory Information and Computer Sciences University of Hawaii Honolulu.
CSC Multiprocessor Programming, Spring, 2011 Chapter 9 – GUI Applications Dr. Dale E. Parson, week 11.
CSC 322 Operating Systems Concepts Lecture - 7: by Ahmed Mumtaz Mustehsan Special Thanks To: Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
13-1 Chapter 13 Concurrency Topics Introduction Introduction to Subprogram-Level Concurrency Semaphores Monitors Message Passing Java Threads C# Threads.
Thread basics. A computer process Every time a program is executed a process is created It is managed via a data structure that keeps all things memory.
Cs431-cotter1 Processes and Threads Tanenbaum 2.1, 2.2 Crowley Chapters 3, 5 Stallings Chapter 3, 4 Silberschaz & Galvin 3, 4.
Swing Threading Nested Classes COMP 401 Fall 2014 Lecture 23 11/25/2014.
1 Why Threads are a Bad Idea (for most purposes) based on a presentation by John Ousterhout Sun Microsystems Laboratories Threads!
Java Threads 1 1 Threading and Concurrent Programming in Java Threads and Swing D.W. Denbo.
Review IS Overview: Data  Inside the application Collections  Outside the application Database XML  Getting/displaying Swing  Communicating.
CHAPTER 6 Threads, Handlers, and Programmatic Movement.
Advanced Operating Systems CS6025 Spring 2016 Processes and Threads (Chapter 2)
Threads and Swing Multithreading. Contents I. Simulation on Inserting and Removing Items in a Combo Box II. Event Dispatch Thread III. Rules for Running.
Java Thread Programming
Chapter 4 – Thread Concepts
Reactive Android Development
Multi-processor Scheduling
Operating Systems (CS 340 D)
OPERATING SYSTEMS CS3502 Fall 2017
Chapter 4 – Thread Concepts
Operating System (013022) Dr. H. Iwidat
Process Management Presented By Aditya Gupta Assistant Professor
Lecture 21 Concurrency Introduction
Lecture 28 Concurrent, Responsive GUIs
Operating Systems (CS 340 D)
Chapter 3: Windows7 Part 2.
Computer System Overview
Model-View-Controller Patterns and Frameworks
System Structure and Process Model
Chapter 3: Windows7 Part 2.
Thread Implementation Issues
Threads Chapter 4.
Android Topics Asynchronous Callsbacks
Chapter 3: Processes.
Chapter 4: Threads.
CS333 Intro to Operating Systems
Model, View, Controller design pattern
Using threads for long running tasks.
Chapter 3: Processes Process Concept Process Scheduling
Chapter 4: Threads.
Operating System Overview
CSC Multiprocessor Programming, Spring, 2011
Presentation transcript:

CSC 480 - Multiprocessor Programming, Spring, 2012 Chapter 9 – GUI Applications Dr. Dale E. Parson, week 11

Event Dispatch Thread GUI Events (user, timer etc.) occur in a GUI event dispatch thread. Method calls among Swing GUI objects must occur confined to this thread. No other thread my directly invoke methods on these GUI objects. The event dispatch thread should not invoke long-running computations outside the GUI. The user interface becomes unresponsive.

Multithreaded GUI Attempts User actions bubble up from the O.S. Application actions bubble down to the O.S., e.g., to repaint a display. Resulting cycles in lock dependencies on thread-sage GUI components tends toward deadlock. Model-view-controller (MVC) pattern can suffer from the same problem. controller -> model -> view (model events paint view) controller -> view -> model (view queries model)

Thread Confinement for GUIs GUI events and updates are sequential. Burden of thread confinement is placed on application programmer. GUI components must be confined inside an encapsulated class or set of classes to maintain thread confinement. Simpler thread confinement to local variables and parameters is not possible because GUI components must outlive the call stack frames that construct them. GUI library must have hooks for interacting with other threads.

Thread confinement in Swing SwingUtilities.isEventDispatchThread Is the current thread the AWT dispatch thread? SwingUtilities.invokeLater Invoke a Runnable on AWT dispatch thread after all pending events. invokeAndWait blocks until Runnable completes. Enqueuing repaint or revalidation request on the event queue can occur on any thread. Adding and removing event listeners can occur on any thread.

Simplest case Event responses either stay in GUI or interact with application objects using short-lived method invocations that are single-threaded or thread safe. Fast methods, no entry of other threads into GUI. GUI update can occur as a result of a change in an MVC model such as a TableModel (javax.swing.table) or TreeModel. Control must not leave the event thread.

Long running GUI tasks These must run in another thread. A cached thread pool is a good choice. User-initiated tasks normally do not grow in number unmanageably. A SingleThreadExecutor is good if you want to limit application concurrency without stalling the GUI. Only one application task runs at a time, but the GUI remains available for interrupting the task. On completion a task must submit a task on the dispatch thread (a Runnable) to update the UI.

Cancellation The user may want to abort a long running task from the GUI. You can interrupt the task directly, but … Submitting a task in an ExecutorService and then cancelling its Future, if necessary, is more organized. Set cancel’s mayInterruptIfRunning to true. Write task code to respond to interrupts.

SwingWorker javax.swing.SwingWorker is an abstract class (scaffolding) for building long-running computations driven from the GUI thread. It implements Runnable, Future<T>, and RunnableFuture<T>. Abstract method doInBackground runs in a background thread, returns T on completion. An application supplies this method, and SwingWorker takes care of propagating the result to the GUI thread.

Shared MVC models TableModel or TreeModel must update the View (GUI) on the dispatch thread. How to get results from another thread into the model? Use a thread-safe implementation of interface TableModel or TreeModel. Push data from the background task to the event thread via invokeLater, where the invoked Runnable updates the model. Let the event thread poll periodically for data from the worker thread.

Split data models A data model with both a presentation domain and an application domain is a split model design. Presentation model is confined to the event thread. Shared model is thread-safe and may be accessed by both the event thread and application threads. Presentation model registers listeners so it can be notified of updates. Event thread updates GUI with a snapshot of the model. Works best with small, infrequently updated model. If models is large or updates occur frequently, incremental updates of the mutations only (as opposed to complete snapshots) may be more efficient.

Split model, native code classes Consider a split-model design when a data model must be shared by more than one thread and implementing a thread-safe data model would be inadvisable because of blocking, consistency, or complexity reasons. Some native code libraries require all accesses to the library to be made by a single thread.