Keeping your Swing Applications Responsive using FoxTrot and Friends Rob Ratcliff.

Slides:



Advertisements
Similar presentations
Review Text Material Covered –Culwin: Chapter 8 threads –Johnson: Chapters 9, 10, 1 through p.44 –Swing: Chapter 1-15 Lessons Learned –Concepts of concurrency/synchronization.
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); }
Java Applets- Using SwingWorker Dave Price and Chris Loftus Computer Science Department University of Wales, Aberystwyth.
Gots ta move dat data and not trash your threads...
Albert Johnson Molly Richardson Andrew Kruth.  Threads Runnable interface sleep()  GUIs repaint() paintComponent()
1 Chapter 7 Graphics and Event Handling. 2 Overview The java.awt and javax.swing packages and their subpackages support graphics and event handling. Many.
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.
March Ron McFadyen1 Design Patterns In software engineering, a design pattern is a generally repeatable solution to a commonly-occurring problem.
1 CMSC 132: Object-Oriented Programming II Nelson Padua-Perez William Pugh Department of Computer Science University of Maryland, College Park.
Integrating Swing with JavaFX
1 Thread Pools. 2 What’s A Thread Pool? A programming technique which we will use. A collection of threads that are created once (e.g. when server starts).
Threads and GUIs Confession: I’ve never liked GUI programming very much – so I haven’t done a lot of it  I don’t like the visual design aspects  But.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L20 (Chapter 24) Multithreading.
Developing User Interfaces (DUI) Chris North cs3724: HCI.
CC1007NI: Further Programming Week 5 Dhruba Sen Module Leader (Islington College)
Swing part-one Eriq Muhammad Adams J
Introduction to Java GUI Creating Graphical User Interfaces © copyright Bobby Hoggard / material may not be redistributed without permission.
Threads some important concepts Simon Lynch
CS12420 – Swing and threads Lynda Thomas
Java Swing, Events and MVC Optional Readings: Eckel’s Thinking in Java: Chap 14 (
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.
1 GUI programming with threads. 2 Threads and Swing Swing is not generally thread-safe: most methods are not synchronized –correct synchronization is.
1 Web Based Programming Section 8 James King 12 August 2003.
GUIs in Java Swing, Events CS2110, SW Development Methods Readings: MSD, Chapter 12 Lab Exercise.
Clicker questions and stuff 12/5/13 CSE 1102 Fall 2013.
Concurrent Programming and Threads Threads Blocking a User Interface.
Synchronizing threads, thread pools, etc.
SWING 101. IF YOU GET LOST - IMPORTANT LINKS  Swing articles:
RMI, and Java GUIs Comments zEveryone should be filling out and turning in group evaluations. These are largely for your protection. It can.
Patterns in programming1. 2 What are patterns? Answers to common design problems. A language used by developers –To discuss answers to design problems.
C20: Threads see also: ThreadedBallWorld, DropTest, Tetris source examples Not covered: advanced stuff like notify/notifyAll.
UID – Event Handling and Listeners Boriana Koleva
IAsyncResult ar = BeginSomething(…); // Do other work, checking ar.IsCompleted int result = EndSomething(ar);
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Multithreading [Modified]
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.
1 Software Construction and Evolution - CSSE 375 Exception Handling – Chaining & Threading Steve Chenoweth Office: Moench Room F220 Phone: (812)
Before class… 下禮拜一交 Proposal – 至多四人一組, 同組同分 – 請勿超過一張 A4 評分標準 創意 技術難度 實用性 User-defined 完整性.
13 June 2001M.Al-Turany/Root20011 Mohammad Al-Turany Go4 GSI Darmstadt 13 June 2001.
Multi-Threading in Java
(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.
Parallel Processing (CS526) Spring 2012(Week 8).  Shared Memory Architecture  Shared Memory Programming & PLs  Java Threads  Preparing the Environment.
DØ Offline Reconstruction and Analysis Control Framework J.Kowalkowski, H.Greenlee, Q.Li, S.Protopopescu, G.Watts, V.White, J.Yu.
Advanced Tools for Multi- Threads Programming Avshalom Elmalech Eliahu Khalastchi 2010.
L6: Threads “the future is parallel” COMP206, Geoff Holmes and Bernhard Pfahringer.
Java Threads 1 1 Threading and Concurrent Programming in Java Threads and Swing D.W. Denbo.
Class on Fragments & threads. Fragments fragment is a modular section of an activity, which has its own lifecycle, receives its own input events, and.
CHAPTER 6 Threads, Handlers, and Programmatic Movement.
Threads and Swing Multithreading. Contents I. Simulation on Inserting and Removing Items in a Combo Box II. Event Dispatch Thread III. Rules for Running.
Threads. Parsing fasta sequences in parallel Threads in GUIs.
PA1 Discussion.
Advanced Topics in Concurrency and Reactive Programming: Asynchronous Programming Majeed Kassis.
CSC Multiprocessor Programming, Spring, 2012
Lecture 6: Process, Thread, Task
Threads, Concurrency, and Parallelism
Lecture 28 Concurrent, Responsive GUIs
Threads Chate Patanothai.
Definitions Concurrent program – Program that executes multiple instructions at the same time. Process – An executing program (the running JVM for Java.
Threads II IS
Android Topics UI Thread and Limited processing resources
Android Topics Threads and the MessageQueue
Constructors, GUI’s(Using Swing) and ActionListner
9. Threads SE2811 Software Component Design
Using threads for long running tasks.
9. Threads SE2811 Software Component Design
Lecture 6: Process, Thread, Task
CMSC 202 Threads.
Presentation transcript:

Keeping your Swing Applications Responsive using FoxTrot and Friends Rob Ratcliff

Swing’s Thread Model Mostly not Thread Safe by design - very few thread safe operations All events added to AWT Queue and processed sequentially Events “popped” off queue by dispatcher running in AWT Thread and delivered to registered listeners Long running listener code results in a non- responsive application

Sequence Diagram of Event Processing

Consequences of direct Swing calls in an alternate thread Deadlock Quirky Painting Sluggish application

Alternatives – Worker Thread and InvokeLater() // some swing code new Thread(new Runnable() { public void run() { // long running task runSwingCode(); } protected void runSwingCode() { SwingUtilities.invokeLater(new Runnable(){ public void run() { // run more swing code } ).start();

Alternatives – SwingWorker // some swing code new SwingWorker() { public Object construct() { // long running code } public void finished() { // more swing code } }.start();

JDialog’s Approach Modal dialog blocks AWT Event Thread Creates another thread to dispatch the events to keep the GUI painting FoxTrot leverages this concept

FoxTrot Approach Similar to JDialog Blocking call, but takes over event queue processing Natural Usage: // some swing code try { Object value = Worker.post(new Task() { public Object run() throws Exception { // long running task }}); } catch (Exception e) {// do something} // more swing code

Dynamic Proxy Client Wrap long running calls a Dynamic Proxy that wraps calls with Foxtrot Avoid sprinkling Foxtrot calls everywhere Assists developers in not having to worry about this stuff Keep this stuff deep down in your framework

Demo Example

Comments on Dynamic Proxy for CallBacks Example Problem – RMI Callback Callback calls Swing methods on RMI dispatch thread to update GUI Inevitable that invokeLater() will be forgotten by some developer on team resulting in an embarassing deadlock! Embed InvokeLater into a proxy around the callback interface (See ChatListenerNotifierFactory.)

References Foxtrot - Simone Bordet - SwingWorker - ds/update.html Threads and Swing - ds/threads1.html ds/threads1.html Dyanamic Proxy -