1 CSCI 6900: Design, Implementation, and Verification of Concurrent Software Eileen Kraemer August 24 th, 2010 The University of Georgia.

Slides:



Advertisements
Similar presentations
Composition CMSC 202. Code Reuse Effective software development relies on reusing existing code. Code reuse must be more than just copying code and changing.
Advertisements

Concurrency 101 Shared state. Part 1: General Concepts 2.
Concurrency and Thread Yoshi. Two Ways to Create Thread Extending class Thread – Actually, we need to override the run method in class Thread Implementing.
Threading Part 4 CS221 – 4/27/09. The Final Date: 5/7 Time: 6pm Duration: 1hr 50mins Location: EPS 103 Bring: 1 sheet of paper, filled both sides with.
Threading Part 3 CS221 – 4/24/09. Teacher Survey Fill out the survey in next week’s lab You will be asked to assess: – The Course – The Teacher – The.
Threading Part 2 CS221 – 4/22/09. Where We Left Off Simple Threads Program: – Start a worker thread from the Main thread – Worker thread prints messages.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Immutable Objects and Classes.
© Andy Wellings, 2004 Roadmap  Introduction  Concurrent Programming  Communication and Synchronization  Completing the Java Model  Overview of the.
Assignment – no class Wednesday All: watch the Google Techtalk “Getting C++ Threads Right” by Hans Boehm at the following link in place of Wednesday’s.
1 Where did the synchronized methods go? Yes, there still exists the synchronized keyword. public synchronized void foo() {} public void foo(){ aLock.lock();
1 Classes, Encapsulation, Methods and Constructors Class definitions Scope of Data –Instance data –Local data The this Reference Encapsulation and Java.
1 Sharing Objects – Ch. 3 Visibility What is the source of the issue? Volatile Dekker’s algorithm Publication and Escape Thread Confinement Immutability.
29-Jun-15 Java Concurrency. Definitions Parallel processes—two or more Threads are running simultaneously, on different cores (processors), in the same.
8.1 Classes & Inheritance Inheritance Objects are created to model ‘things’ Sometimes, ‘things’ may be different, but still have many attributes.
Concurrency with Java Varadha Sundaram. Programming Paradigms Single Process Multi Process Multi Core/Multi Thread.
1 CSCI 6900: Design, Implementation, and Verification of Concurrent Software Eileen Kraemer August 19 th, 2010 The University of Georgia.
Chapter 6 Class Inheritance F Superclasses and Subclasses F Keywords: super F Overriding methods F The Object Class F Modifiers: protected, final and abstract.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
1 Java Inheritance. 2 Inheritance On the surface, inheritance is a code re-use issue. –we can extend code that is already written in a manageable manner.
50.003: Elements of Software Construction Week 8 Composing Thread-safe Objects.
Threading and Concurrency Issues ● Creating Threads ● In Java ● Subclassing Thread ● Implementing Runnable ● Synchronization ● Immutable ● Synchronized.
Concurrency Computer users take it for granted that their systems can do more than one thing at a time. They assume that they can continue to work in a.
SPL/2010 Safety 1. SPL/2010 system designing for concurrent execution environments ● system: collection of objects and their interactions ● system properties:
Practical OOP using Java Basis Faqueer Tanvir Ahmed, 08 Jan 2012.
CH 8 : Enhancing Classes - Review QUICK REVIEW : A Class defines an entity’s (Object’s) data and the actions or behaviors (Methods) associated with that.
Optimistic Design 1. Guarded Methods Do something based on the fact that one or more objects have particular states  Make a set of purchases assuming.
10-Nov-15 Java Object Oriented Programming What is it?
Session 16 Pinball Game Construction Kit:. Pinball Version 1 Replaced the fire button with a mouse event. Multiple balls can be in the air at once. –Uses.
Concurrency in Java Brad Vander Zanden. Processes and Threads Process: A self-contained execution environment Thread: Exists within a process and shares.
Sharing Objects  Synchronization  Atomicity  Specifying critical sections  Memory visibility  One thread’s modification seen by the other  Visibility.
1 CSCI 6900: Design, Implementation, and Verification of Concurrent Software Eileen Kraemer August 24 th, 2010 The University of Georgia.
Session 7 Methods Strings Constructors this Inheritance.
Programmeren 1 6 september 2010 HOORCOLLEGE 2: INTERACTIE EN CONDITIES PROGRAMMEREN 1 6 SEPTEMBER 2009 Software Systems - Programming1 Programming.
Inheritance (Part 5) Odds and ends 1. Static Methods and Inheritance  there is a significant difference between calling a static method and calling a.
COMPSCI 230 S2C 2015 Software Design and Construction Synchronization (cont.) Lecture 4 of Theme C.
Session 13 Pinball Game Construction Kit (Version 3):
Introduction to Java Chapter 7 - Classes & Object-oriented Programming1 Chapter 7 Classes and Object-Oriented Programming.
08 Encapsulation and Abstraction. 2 Contents Defining Abstraction Levels of Abstraction Class as Abstraction Defining a Java Class Instantiating a Class.
Software Design Patterns Curtsy: Fahad Hassan (TxLabs)
This recitation 1 An interesting point about A3: Using previous methods to avoid work in programming and debugging. How much time did you spend writing.
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
Threads. Objectives You must be able to answer the following questions –What code does a thread execute? –What states can a thread be in? –How does a.
13-1 Chapter 13 Concurrency Topics Introduction Introduction to Subprogram-Level Concurrency Semaphores Monitors Message Passing Java Threads C# Threads.
Access Modifiers Control which classes use a feature Only class-level variables may be controlled by access modifiers Modifiers 1. public 2. protected.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
System Programming Practical Session 4: Concurrency / Safety.
Object orientation and Packaging in Java Object Orientation and Packaging Introduction: After completing this chapter, you will be able to identify.
Chapter 7 Classes and Methods III: Static Methods and Variables Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition)
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
5.1 Basics of defining and using classes A review of class and object definitions A class is a template or blueprint for an object A class defines.
Kyung Hee University Class Diagramming Notation OOSD 담당조교 석사과정 이정환.
Concurrency (Threads) Threads allow you to do tasks in parallel. In an unthreaded program, you code is executed procedurally from start to finish. In a.
Software Design 13.1 From controller to threads l Threads are lightweight processes (what’s a process?)  Threads are part of a single program, share state.
Java.util.concurrent package. concurrency utilities packages provide a powerful, extensible framework of high-performance threading utilities such as.
Sun Proprietary/Confidential: Internal Use Only 1 Multi-Threading Primer Byron Nevins December 10, 2007.
OOP: Encapsulation &Abstraction
More Sophisticated Behavior
Lecture 8 Thread Safety.
Functional Programming with Java
More on Thread Safety CSE451 Andrew Whitaker.
Java Concurrency 17-Jan-19.
Java Concurrency.
Java Concurrency.
CS 112 Programming 2 Lecture 02 Abstract Classes & Interfaces (2)
Lecture 8 Thread Safety.
Java Concurrency 29-May-19.
CSE 332: Concurrency and Locks
some important concepts
Threads and concurrency / Safety
Presentation transcript:

1 CSCI 6900: Design, Implementation, and Verification of Concurrent Software Eileen Kraemer August 24 th, 2010 The University of Georgia

2 Java Threads & Concurrency, continued  Liveness Liveness Deadlock Starvation and Livelock  Guarded Blocks Guarded Blocks  Immutable Objects Immutable Objects A Synchronized Class Example A Strategy for Defining Immutable Objects  High Level Concurrency Objects High Level Concurrency Objects Lock Objects Executors  Executor Interfaces Executor Interfaces  Thread Pools Thread Pools  Concurrent Collections Concurrent Collections  Atomic V ariables Atomic V ariables

3 Immutable Objects  state cannot change after it is constructed.  useful in concurrent applications.  Since they cannot change state, they cannot be : corrupted by thread interference observed in an inconsistent state.

4 SynchronizedRGB  See code handout …  See any problems???

5 What if …. Thread 1: SynchronizedRGB color = new SynchronizedRGB(0, 0, 0, "Pitch Black");... //Statement 1 int myColorInt = color.getRGB(); //Statement 2 String myColorName color.getName(); Thread 2: //In between.. Color.set(someColor );

6 Solution for a mutable objects synchronized (color) { int myColorInt = color.getRGB(); String myColorName = color.getName(); }

7 Immutable objects … 1.Don't provide "setter" methods — methods that modify fields or objects referred to by fields. 2.Make all fields final and private. 3.Don't allow subclasses to override methods. The simplest way to do this is to declare the class as final. A more sophisticated approach is to make the constructor private and construct instances in factory methods. 4.If the instance fields include references to mutable objects, don't allow those objects to be changed: Don't provide methods that modify the mutable objects. Don't share references to the mutable objects. Never store references to external, mutable objects passed to the constructor; if necessary, create copies, and store references to the copies. Similarly, create copies of your internal mutable objects when necessary to avoid returning the originals in your methods.

8 To make SynchronizedRGB immutable: 1.There are two setter methods in this class. The first one, set, arbitrarily transforms the object, and has no place in an immutable version of the class. The second one, invert, can be adapted by having it create a new object instead of modifying the existing one. 2.All fields are already private; they are further qualified as final. 3.The class itself is declared final. 4.Only one field refers to an object, and that object is itself immutable. Therefore, no safeguards against changing the state of "contained" mutable objects are necessary.

9 See modified class ….

10 High Level Concurrency Objects  Lock objects  Executors  Concurrent collections  Atomic variables

11 Lock objects  “synchronized” uses simple type of reentrant lock  Other locking idioms can be found in: java.util.concurrent.locks  Basic interface: Lock Only one thread can own at a time Have associated Condition objects Support a wait/notify mechanism Special features  Can check if lock is available (tryLock) and then back out  lockInterruptibly – backs out if another thread sends interrupt before lock is acquired

12 New & improved Alphonse and Gaston  See Safelock example

13 Thursday …  Executors  Concurrent Collections  Atomic Variables