SlideShare a Scribd company logo
Concurrent
Programming
01
Sachintha Gunasena MBCS
http://lk.linkedin.com/in/sachinthadtg
Learning Outcomes
Sachintha Gunasena MBCS
http://lk.linkedin.com/in/sachinthadtg
Learning Outcomes
• Demonstrate foundational computing knowledge of
concurrent systems, their performance opportunities and
how to implement them using:
• Java concurrent features and their semantics
• Java packages and APIs for concurrent programs
• Conventional synchronisation algorithms, data-
structures and APIs
• Wait-free and lock-free synchronisation controls.
Learning Outcomes Cont.d
• Apply knowledge of computing principles and technical
skills to parallelise tasks to improve their performance
and response characteristics by:
• Using abstraction and computational thinking
• Developing, implementing and testing the
effectiveness of alternate Java programs with
different levels of concurrency
• Critiquing the approach used to solve a problem by
evaluating its strengths and weaknesses
starting with the
basics…
Programming
• the process of writing computer programs.
• example
• Output
class First {
public static void main(String[] arguments) {
System.out.println("Let's do something using Java technology.");
}
}
OOP
• Object
• An object is a software bundle of related state and behavior. Software objects are often
used to model the real-world objects that you find in everyday life. This lesson explains how
state and behavior are represented within an object, introduces the concept of data
encapsulation, and explains the benefits of designing your software in this manner.
• Class
• A class is a blueprint or prototype from which objects are created. This section defines a
class that models the state and behavior of a real-world object. It intentionally focuses on
the basics, showing how even a simple class can cleanly model state and behavior.
• Inheritance
• Inheritance provides a powerful and natural mechanism for organizing and structuring your
software. This section explains how classes inherit state and behavior from their
superclasses, and explains how to derive one class from another using the simple syntax
provided by the Java programming language.
OOP Cont.d
• Encapsulation
• If a class disallows calling code from accessing internal object data and forces
access through methods only, this is a strong form of abstraction or information
hiding known as encapsulation
• Interface
• An interface is a contract between a class and the outside world. When a class
implements an interface, it promises to provide the behavior published by that
interface. This section defines a simple interface and explains the necessary
changes for any class that implements it.
• Package
• A package is a namespace for organizing classes and interfaces in a logical manner.
Placing your code into packages makes large software projects easier to manage.
This section explains why this is useful, and introduces you to the Application
Programming Interface (API) provided by the Java platform.
Concurrency
• a property of systems in which several computations are
executing simultaneously, and potentially interacting with
each other.
• The computations may be executing on multiple cores in the
same chip, preemptively time-shared threads on the same
processor, or executed on physically separated processors.
• A number of mathematical models have been developed for
general concurrent computation including Petri nets, process
calculi, the Parallel Random Access Machine model, the
Actor model and the Reo Coordination Language.
Concurrent Programming
• Concurrent object-oriented programming is a
programming paradigm which combines object-
oriented programming (OOP) together with
concurrency.
• While numerous programming languages, such as
Java, combine OOP with concurrency mechanisms
like threads, the phrase "concurrent object-oriented
programming" primarily refers to systems where
objects themselves are a concurrency primitive, such
as when objects are combined with the actor model.
Parallel Computing
• a form of computation in which many calculations
are carried out simultaneously, operating on the
principle that large problems can often be divided
into smaller ones, which are then solved at the
same time.
Concurrent vs Parallel
• you can have two threads (or processes) executing
concurrently on the same core through context switching.
• When the two threads (or processes) are executed on two
different cores (or processors), you have parallelism.
• in concurrency, parallelism is only "virtual", while the other
true parallelism.
• Therefore, every parallel program is concurrent, but the
converse is not necessarily true
Why Concurrency?
• Efficiency
• Time (load sharing)
• Cost (resource sharing)
• Availability
• Multiple access
• Convenience
• • Perform several tasks at once
• Modeling power
• Describing systems that are inherently parallel
Real World Example
• Computer systems are used for modeling objects in
the real world
• Object-oriented programming
• The world often includes parallel operation
• example:
• Limited number of seats on the same plane
• Several booking agents active at the same time
Terms
• Multiprocessing
• the use of more than one processing unit in a
system
• Parallel execution
• processes running at the same time
Terms Cont.d
• Interleaving
• several tasks active, only one running at a time
• Multitasking
• the OS runs interleaved executions
• Concurrency
• multiprocessing, multitasking, or any combination
Moore’s Law
Why it matters?
• The “end of Moore’s law as we knew it” has important implications on the
software construction process
• Computing is taking an irreversible step toward parallel architectures
• Hardware construction of ever faster sequential CPUs has hit physical
limits
• Clock speed no longer increases for every new processor generation
• Moore’s Law expresses itself as exponentially increasing number of
processing cores per chip
• If we want programs to run faster on the next processor generation, the
software must exploit more concurrency
Amdahl’s Law
Amdahl’s Law Cont.d
• We go from 1 processor to n. What gain may we
expect?
• Amdahl’s law severely limits our hopes!
• Define gain as:
• speed up = ( 1 / (( 1-p)+( p/n)) )
• where p = parallelizable %; n= number of processors
• Not everything can be parallelized!
Types of Parallel
Computation
• Flynn’s taxonomy: classification of computer
architectures
• Considers relationship of instruction streams to
data streams:
• SISD: No parallelism (uniprocessor)
• SIMD: Vector processor, GPU
• MIMD: Multiprocessing (predominant today)
MIMD Variants
• SPMD (Single Program Multiple Data):
• All processors run same program, but at
independent speeds; no lockstep as in SIMD
• MPMD (Multiple Program Multiple Data):
• Often manager/worker strategy: manager
distributes tasks, workers return result to
manager
Shared Memory Model
• All processors share a common memory
• Shared-memory communication
Memory
Processor
1
Processor
2
Processor
4
Processor
3
Distributed Memory Model
• Each processor has own local memory, inaccessible to
others
• Message passing communication
• Common for SPMD architecture
Process
or
Process
or
Process
or
Memory MemoryMemory
Message Passing
Client Server Model
• Specific case of the distributed model
• Examples: Database-centered systems, World-Wide
Web
Process
or
Process
or
Process
or
Memory Memory
Memory
SCOOP Mechanism
• Simple Concurrent Object-Oriented Programming
• Evolved through previous two decades; CACM (1993) and chap.
32 of Object-Oriented Software Construction, 2nd edition, 1997
• Prototype-implementation at ETH in 2007
• Implementation integrated within EiffelStudio in 2011 (by Eiffel
Software)
• Current reference: ETH PhD Thesis by Piotr Nienaltowski, 2008;
articles by Benjamin Morandi, Sebastian Nanz and Bertrand
Meyer, 2010-2011
SCOOP Preview: a
sequential program
transfer (source, target: ACCOUNT;
amount: INTEGER)
-- If possible, transfer amount from source to target.
do
if source.balance >= amount then
source.withdraw (amount)
target.deposit (amount)
end
end
Typical calls:
transfer (acc1, acc2, 100)
transfer (acc1, acc3, 100)
In a concurrent setting, using
SCOOP
transfer (source, target: separate ACCOUNT;
amount: INTEGER)
-- If possible, transfer amount from source to target.
do
if source.balance >= amount then
source.withdraw (amount)
target.deposit (amount)
end
end
Typical calls:
transfer (acc1, acc2, 100)
transfer (acc1, acc3, 100)
A better SCOOP version
transfer (source, target: separate ACCOUNT;
amount: INTEGER)
-- Transfer amount from source to target.
require
source.balance >= amount
do
source.withdraw (amount)
target.deposit (amount)
ensure
source.balance = old source.balance – amount
target.balance = old target.balance + amount
end
Dining Philosophers
• find out about it…
Programming: Then &
Now
Sequential Programming
• Used to be messy
• Still hard but key improvements:
• Structured programming
• Data abstraction & object technology
• Design by Contract
• Genericity, multiple inheritance
• Architectural techniques
Concurrent Programming
• Used to be messy
• Example: threading models in most popular
approaches
• Development level: sixties/seventies
• Only understandable through operational
reasoning
References
• http://www.javaworld.com/article/2078679/java-concurrency/java-concurrency-modern-
threading-for-not-quite-beginners.html
• https://books.google.mv/books?id=-
x1S4neCSOYC&pg=PA5&lpg=PA5&dq=what+is+using+concurrency+constructs&source=bl&ot
s=Dxdk47Ddy-
&sig=ZxzRD163royyROmEOF2lAtSZBz8&hl=en&sa=X&ved=0CEkQ6AEwBmoVChMIx-
rc1ZbYxwIVQQeOCh3LkguH#v=onepage&q=what%20is%20using%20concurrency%20constru
cts&f=false
• http://book.realworldhaskell.org/read/concurrent-and-multicore-programming.html
• https://books.google.mv/books?id=mHozgJ7ngq0C&pg=PA1&lpg=PA1&dq=what+is+using+con
currency+constructs&source=bl&ots=TOT_g-
IESw&sig=xSG7JzGquRD9NZmnbkt6tv6Vr2A&hl=en&sa=X&ved=0CFcQ6AEwCWoVChMIx-
rc1ZbYxwIVQQeOCh3LkguH#v=onepage&q=what%20is%20using%20concurrency%20constru
cts&f=false
• http://gee.cs.oswego.edu/dl/cpj/mechanics.html
• Read stack overflow / java documentation / etc
Next Up…
• Concurrent Programming…
Sachintha Gunasena MBCS
http://lk.linkedin.com/in/sachinthadtg
Thank you.
Sachintha Gunasena MBCS
http://lk.linkedin.com/in/sachinthadtg

More Related Content

PPTX
Concurrency in Java
Allan Huang
 
PDF
Concurrency
Sri Prasanna
 
PPTX
Concurrency Programming in Java - 07 - High-level Concurrency objects, Lock O...
Sachintha Gunasena
 
PDF
Concurrent/ parallel programming
Tausun Akhtary
 
PPTX
Concurrent programming
Rahul Singh
 
PDF
Working With Concurrency In Java 8
Heartin Jacob
 
PPT
Parallel programming
Swain Loda
 
PPTX
Concurrency Programming in Java - 05 - Processes and Threads, Thread Objects,...
Sachintha Gunasena
 
Concurrency in Java
Allan Huang
 
Concurrency
Sri Prasanna
 
Concurrency Programming in Java - 07 - High-level Concurrency objects, Lock O...
Sachintha Gunasena
 
Concurrent/ parallel programming
Tausun Akhtary
 
Concurrent programming
Rahul Singh
 
Working With Concurrency In Java 8
Heartin Jacob
 
Parallel programming
Swain Loda
 
Concurrency Programming in Java - 05 - Processes and Threads, Thread Objects,...
Sachintha Gunasena
 

What's hot (14)

PPT
Java New Evolution
Allan Huang
 
PPTX
Concurrency Programming in Java - 06 - Thread Synchronization, Liveness, Guar...
Sachintha Gunasena
 
PPTX
Multi-Threading
Robert MacLean
 
ODP
Multithreading 101
Tim Penhey
 
PPTX
.NET: Thread Synchronization Constructs
Sasha Kravchuk
 
PPTX
.NET Multithreading/Multitasking
Sasha Kravchuk
 
PDF
gcdtmp
TheFoolish Man
 
PPTX
Threading in C#
Medhat Dawoud
 
PPT
multithreading
Rajkattamuri
 
PDF
Java Multithreading Using Executors Framework
Arun Mehra
 
PPTX
Concurrency with java
Hoang Nguyen
 
PPT
Java
mdfkhan625
 
PPT
Java
Khasim Cise
 
PPT
Multithreading
F K
 
Java New Evolution
Allan Huang
 
Concurrency Programming in Java - 06 - Thread Synchronization, Liveness, Guar...
Sachintha Gunasena
 
Multi-Threading
Robert MacLean
 
Multithreading 101
Tim Penhey
 
.NET: Thread Synchronization Constructs
Sasha Kravchuk
 
.NET Multithreading/Multitasking
Sasha Kravchuk
 
Threading in C#
Medhat Dawoud
 
multithreading
Rajkattamuri
 
Java Multithreading Using Executors Framework
Arun Mehra
 
Concurrency with java
Hoang Nguyen
 
Multithreading
F K
 
Ad

Similar to Concurrency Programming in Java - 01 - Introduction to Concurrency Programming (20)

PPT
Share Unit 1- Basic concept of object-oriented-programming.ppt
hannahrroselin95
 
PDF
Our Concurrent Past; Our Distributed Future
C4Media
 
PPTX
Unit - I Intro. to OOP Concepts and Control Structure -OOP and CG (2024 Patte...
babasahebgaikwad8
 
PPTX
java oops and java very important for .pptx
cherukuriyuvaraju9
 
PPTX
java oops compilation object class inheritance.pptx
CHERUKURIYUVARAJU209
 
PPTX
1 intro
abha48
 
PPT
Object Oriented Methodology in Java (Lecture-1)
Md. Mujahid Islam
 
PPTX
Object Oriented Design and Programming Unit-01
Sivakumar M
 
PPT
Unit 1- Basic concept of object-oriented-programming.ppt
hannahroseline2
 
DOC
Object
guest94b187c
 
PDF
UNIT1- OBJECT ORIENTED PROGRAMMING IN JAVA- AIML IT-SPPU
ApurvaLaddha
 
PPTX
Parallel architecture &programming
Ismail El Gayar
 
PPTX
Different paradigms for problem solving.pptx
iitjeesooraj
 
PDF
Computer_Programming_Part_II_Segment_01.pdf
et243047
 
DOCX
Unit1 jaava
mrecedu
 
PDF
Mathematical foundations of Multithreaded programming concepts in Java lang...
AM Publications,India
 
PPTX
Introduction to Software - Coder Forge - John Mulhall
John Mulhall
 
PDF
Concurrency Issues in Object-Oriented Modeling
IRJET Journal
 
PPTX
Programming using C++ - slides.pptx
HeadoftheDepartment
 
Share Unit 1- Basic concept of object-oriented-programming.ppt
hannahrroselin95
 
Our Concurrent Past; Our Distributed Future
C4Media
 
Unit - I Intro. to OOP Concepts and Control Structure -OOP and CG (2024 Patte...
babasahebgaikwad8
 
java oops and java very important for .pptx
cherukuriyuvaraju9
 
java oops compilation object class inheritance.pptx
CHERUKURIYUVARAJU209
 
1 intro
abha48
 
Object Oriented Methodology in Java (Lecture-1)
Md. Mujahid Islam
 
Object Oriented Design and Programming Unit-01
Sivakumar M
 
Unit 1- Basic concept of object-oriented-programming.ppt
hannahroseline2
 
Object
guest94b187c
 
UNIT1- OBJECT ORIENTED PROGRAMMING IN JAVA- AIML IT-SPPU
ApurvaLaddha
 
Parallel architecture &programming
Ismail El Gayar
 
Different paradigms for problem solving.pptx
iitjeesooraj
 
Computer_Programming_Part_II_Segment_01.pdf
et243047
 
Unit1 jaava
mrecedu
 
Mathematical foundations of Multithreaded programming concepts in Java lang...
AM Publications,India
 
Introduction to Software - Coder Forge - John Mulhall
John Mulhall
 
Concurrency Issues in Object-Oriented Modeling
IRJET Journal
 
Programming using C++ - slides.pptx
HeadoftheDepartment
 
Ad

More from Sachintha Gunasena (16)

PPTX
Entrepreneurship and Commerce in IT - 14 - Web Marketing Communications
Sachintha Gunasena
 
PPTX
Entrepreneurship and Commerce in IT - 13 - The Internet Audience, consumer be...
Sachintha Gunasena
 
PPTX
Entrepreneurship & Commerce in IT - 12 - Web Payments
Sachintha Gunasena
 
PPTX
Concurrency Programming in Java - 03 - Essentials of Java Part 2
Sachintha Gunasena
 
PPTX
Concurrency Programming in Java - 02 - Essentials of Java Part 1
Sachintha Gunasena
 
PPTX
Entrepreneurship & Commerce in IT - 11 - Security & Encryption
Sachintha Gunasena
 
PPTX
Entrepreneurship & Commerce in IT - 08 - E-Commerce business models and concepts
Sachintha Gunasena
 
PPTX
Entrepreneurship & Commerce in IT - 10 - The Internet today and How to build ...
Sachintha Gunasena
 
PPTX
Entrepreneurship & Commerce in IT - 09 - The internet and the world wide web
Sachintha Gunasena
 
PPTX
Entrepreneurship and Commerce in IT - 07 - Introduction to E-Commerce I - e-c...
Sachintha Gunasena
 
PPT
Entrepreneurship and Commerce in IT - 06 - Funding, Expanding, and Exit Strat...
Sachintha Gunasena
 
PPT
Entrepreneurship and Commerce in IT - 05 - Marketing, Technology and Marketin...
Sachintha Gunasena
 
PPT
Entrepreneurship & Commerce in IT - 01 - Introduction in to Entrepreneurship,...
Sachintha Gunasena
 
PPT
Entrepreneurship & Commerce in IT - 02 - Basic Concepts of Entrepreneurship, ...
Sachintha Gunasena
 
PPT
Entrepreneurship & Commerce in IT - 04 - Marketing Plan, Marketing 7 P's, STP...
Sachintha Gunasena
 
PPT
Entrepreneurship & Commerce in IT - 03 - Writing a Business Plan, Creating a ...
Sachintha Gunasena
 
Entrepreneurship and Commerce in IT - 14 - Web Marketing Communications
Sachintha Gunasena
 
Entrepreneurship and Commerce in IT - 13 - The Internet Audience, consumer be...
Sachintha Gunasena
 
Entrepreneurship & Commerce in IT - 12 - Web Payments
Sachintha Gunasena
 
Concurrency Programming in Java - 03 - Essentials of Java Part 2
Sachintha Gunasena
 
Concurrency Programming in Java - 02 - Essentials of Java Part 1
Sachintha Gunasena
 
Entrepreneurship & Commerce in IT - 11 - Security & Encryption
Sachintha Gunasena
 
Entrepreneurship & Commerce in IT - 08 - E-Commerce business models and concepts
Sachintha Gunasena
 
Entrepreneurship & Commerce in IT - 10 - The Internet today and How to build ...
Sachintha Gunasena
 
Entrepreneurship & Commerce in IT - 09 - The internet and the world wide web
Sachintha Gunasena
 
Entrepreneurship and Commerce in IT - 07 - Introduction to E-Commerce I - e-c...
Sachintha Gunasena
 
Entrepreneurship and Commerce in IT - 06 - Funding, Expanding, and Exit Strat...
Sachintha Gunasena
 
Entrepreneurship and Commerce in IT - 05 - Marketing, Technology and Marketin...
Sachintha Gunasena
 
Entrepreneurship & Commerce in IT - 01 - Introduction in to Entrepreneurship,...
Sachintha Gunasena
 
Entrepreneurship & Commerce in IT - 02 - Basic Concepts of Entrepreneurship, ...
Sachintha Gunasena
 
Entrepreneurship & Commerce in IT - 04 - Marketing Plan, Marketing 7 P's, STP...
Sachintha Gunasena
 
Entrepreneurship & Commerce in IT - 03 - Writing a Business Plan, Creating a ...
Sachintha Gunasena
 

Recently uploaded (20)

PPTX
classification of computer and basic part of digital computer
ravisinghrajpurohit3
 
PPTX
Presentation about Database and Database Administrator
abhishekchauhan86963
 
PDF
Key Features to Look for in Arizona App Development Services
Net-Craft.com
 
PDF
Summary Of Odoo 18.1 to 18.4 : The Way For Odoo 19
CandidRoot Solutions Private Limited
 
PPTX
Visualising Data with Scatterplots in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PPTX
TRAVEL APIs | WHITE LABEL TRAVEL API | TOP TRAVEL APIs
philipnathen82
 
PDF
Using licensed Data Loss Prevention (DLP) as a strategic proactive data secur...
Q-Advise
 
PDF
ChatPharo: an Open Architecture for Understanding How to Talk Live to LLMs
ESUG
 
PPTX
slidesgo-unlocking-the-code-the-dynamic-dance-of-variables-and-constants-2024...
kr2589474
 
PDF
Enhancing Healthcare RPM Platforms with Contextual AI Integration
Cadabra Studio
 
PDF
10 posting ideas for community engagement with AI prompts
Pankaj Taneja
 
PDF
Salesforce Implementation Services Provider.pdf
VALiNTRY360
 
PDF
New Download FL Studio Crack Full Version [Latest 2025]
imang66g
 
PPTX
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
bbedford2
 
PDF
MiniTool Power Data Recovery Crack New Pre Activated Version Latest 2025
imang66g
 
PDF
What to consider before purchasing Microsoft 365 Business Premium_PDF.pdf
Q-Advise
 
PPTX
Odoo Integration Services by Candidroot Solutions
CandidRoot Solutions Private Limited
 
PDF
Exploring AI Agents in Process Industries
amoreira6
 
PDF
On Software Engineers' Productivity - Beyond Misleading Metrics
Romén Rodríguez-Gil
 
PPTX
Presentation about variables and constant.pptx
safalsingh810
 
classification of computer and basic part of digital computer
ravisinghrajpurohit3
 
Presentation about Database and Database Administrator
abhishekchauhan86963
 
Key Features to Look for in Arizona App Development Services
Net-Craft.com
 
Summary Of Odoo 18.1 to 18.4 : The Way For Odoo 19
CandidRoot Solutions Private Limited
 
Visualising Data with Scatterplots in IBM SPSS Statistics.pptx
Version 1 Analytics
 
TRAVEL APIs | WHITE LABEL TRAVEL API | TOP TRAVEL APIs
philipnathen82
 
Using licensed Data Loss Prevention (DLP) as a strategic proactive data secur...
Q-Advise
 
ChatPharo: an Open Architecture for Understanding How to Talk Live to LLMs
ESUG
 
slidesgo-unlocking-the-code-the-dynamic-dance-of-variables-and-constants-2024...
kr2589474
 
Enhancing Healthcare RPM Platforms with Contextual AI Integration
Cadabra Studio
 
10 posting ideas for community engagement with AI prompts
Pankaj Taneja
 
Salesforce Implementation Services Provider.pdf
VALiNTRY360
 
New Download FL Studio Crack Full Version [Latest 2025]
imang66g
 
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
bbedford2
 
MiniTool Power Data Recovery Crack New Pre Activated Version Latest 2025
imang66g
 
What to consider before purchasing Microsoft 365 Business Premium_PDF.pdf
Q-Advise
 
Odoo Integration Services by Candidroot Solutions
CandidRoot Solutions Private Limited
 
Exploring AI Agents in Process Industries
amoreira6
 
On Software Engineers' Productivity - Beyond Misleading Metrics
Romén Rodríguez-Gil
 
Presentation about variables and constant.pptx
safalsingh810
 

Concurrency Programming in Java - 01 - Introduction to Concurrency Programming

  • 2. Learning Outcomes Sachintha Gunasena MBCS http://lk.linkedin.com/in/sachinthadtg
  • 3. Learning Outcomes • Demonstrate foundational computing knowledge of concurrent systems, their performance opportunities and how to implement them using: • Java concurrent features and their semantics • Java packages and APIs for concurrent programs • Conventional synchronisation algorithms, data- structures and APIs • Wait-free and lock-free synchronisation controls.
  • 4. Learning Outcomes Cont.d • Apply knowledge of computing principles and technical skills to parallelise tasks to improve their performance and response characteristics by: • Using abstraction and computational thinking • Developing, implementing and testing the effectiveness of alternate Java programs with different levels of concurrency • Critiquing the approach used to solve a problem by evaluating its strengths and weaknesses
  • 6. Programming • the process of writing computer programs. • example • Output class First { public static void main(String[] arguments) { System.out.println("Let's do something using Java technology."); } }
  • 7. OOP • Object • An object is a software bundle of related state and behavior. Software objects are often used to model the real-world objects that you find in everyday life. This lesson explains how state and behavior are represented within an object, introduces the concept of data encapsulation, and explains the benefits of designing your software in this manner. • Class • A class is a blueprint or prototype from which objects are created. This section defines a class that models the state and behavior of a real-world object. It intentionally focuses on the basics, showing how even a simple class can cleanly model state and behavior. • Inheritance • Inheritance provides a powerful and natural mechanism for organizing and structuring your software. This section explains how classes inherit state and behavior from their superclasses, and explains how to derive one class from another using the simple syntax provided by the Java programming language.
  • 8. OOP Cont.d • Encapsulation • If a class disallows calling code from accessing internal object data and forces access through methods only, this is a strong form of abstraction or information hiding known as encapsulation • Interface • An interface is a contract between a class and the outside world. When a class implements an interface, it promises to provide the behavior published by that interface. This section defines a simple interface and explains the necessary changes for any class that implements it. • Package • A package is a namespace for organizing classes and interfaces in a logical manner. Placing your code into packages makes large software projects easier to manage. This section explains why this is useful, and introduces you to the Application Programming Interface (API) provided by the Java platform.
  • 9. Concurrency • a property of systems in which several computations are executing simultaneously, and potentially interacting with each other. • The computations may be executing on multiple cores in the same chip, preemptively time-shared threads on the same processor, or executed on physically separated processors. • A number of mathematical models have been developed for general concurrent computation including Petri nets, process calculi, the Parallel Random Access Machine model, the Actor model and the Reo Coordination Language.
  • 10. Concurrent Programming • Concurrent object-oriented programming is a programming paradigm which combines object- oriented programming (OOP) together with concurrency. • While numerous programming languages, such as Java, combine OOP with concurrency mechanisms like threads, the phrase "concurrent object-oriented programming" primarily refers to systems where objects themselves are a concurrency primitive, such as when objects are combined with the actor model.
  • 11. Parallel Computing • a form of computation in which many calculations are carried out simultaneously, operating on the principle that large problems can often be divided into smaller ones, which are then solved at the same time.
  • 12. Concurrent vs Parallel • you can have two threads (or processes) executing concurrently on the same core through context switching. • When the two threads (or processes) are executed on two different cores (or processors), you have parallelism. • in concurrency, parallelism is only "virtual", while the other true parallelism. • Therefore, every parallel program is concurrent, but the converse is not necessarily true
  • 13. Why Concurrency? • Efficiency • Time (load sharing) • Cost (resource sharing) • Availability • Multiple access • Convenience • • Perform several tasks at once • Modeling power • Describing systems that are inherently parallel
  • 14. Real World Example • Computer systems are used for modeling objects in the real world • Object-oriented programming • The world often includes parallel operation • example: • Limited number of seats on the same plane • Several booking agents active at the same time
  • 15. Terms • Multiprocessing • the use of more than one processing unit in a system • Parallel execution • processes running at the same time
  • 16. Terms Cont.d • Interleaving • several tasks active, only one running at a time • Multitasking • the OS runs interleaved executions • Concurrency • multiprocessing, multitasking, or any combination
  • 18. Why it matters? • The “end of Moore’s law as we knew it” has important implications on the software construction process • Computing is taking an irreversible step toward parallel architectures • Hardware construction of ever faster sequential CPUs has hit physical limits • Clock speed no longer increases for every new processor generation • Moore’s Law expresses itself as exponentially increasing number of processing cores per chip • If we want programs to run faster on the next processor generation, the software must exploit more concurrency
  • 20. Amdahl’s Law Cont.d • We go from 1 processor to n. What gain may we expect? • Amdahl’s law severely limits our hopes! • Define gain as: • speed up = ( 1 / (( 1-p)+( p/n)) ) • where p = parallelizable %; n= number of processors • Not everything can be parallelized!
  • 21. Types of Parallel Computation • Flynn’s taxonomy: classification of computer architectures • Considers relationship of instruction streams to data streams: • SISD: No parallelism (uniprocessor) • SIMD: Vector processor, GPU • MIMD: Multiprocessing (predominant today)
  • 22. MIMD Variants • SPMD (Single Program Multiple Data): • All processors run same program, but at independent speeds; no lockstep as in SIMD • MPMD (Multiple Program Multiple Data): • Often manager/worker strategy: manager distributes tasks, workers return result to manager
  • 23. Shared Memory Model • All processors share a common memory • Shared-memory communication Memory Processor 1 Processor 2 Processor 4 Processor 3
  • 24. Distributed Memory Model • Each processor has own local memory, inaccessible to others • Message passing communication • Common for SPMD architecture Process or Process or Process or Memory MemoryMemory Message Passing
  • 25. Client Server Model • Specific case of the distributed model • Examples: Database-centered systems, World-Wide Web Process or Process or Process or Memory Memory Memory
  • 26. SCOOP Mechanism • Simple Concurrent Object-Oriented Programming • Evolved through previous two decades; CACM (1993) and chap. 32 of Object-Oriented Software Construction, 2nd edition, 1997 • Prototype-implementation at ETH in 2007 • Implementation integrated within EiffelStudio in 2011 (by Eiffel Software) • Current reference: ETH PhD Thesis by Piotr Nienaltowski, 2008; articles by Benjamin Morandi, Sebastian Nanz and Bertrand Meyer, 2010-2011
  • 27. SCOOP Preview: a sequential program transfer (source, target: ACCOUNT; amount: INTEGER) -- If possible, transfer amount from source to target. do if source.balance >= amount then source.withdraw (amount) target.deposit (amount) end end Typical calls: transfer (acc1, acc2, 100) transfer (acc1, acc3, 100)
  • 28. In a concurrent setting, using SCOOP transfer (source, target: separate ACCOUNT; amount: INTEGER) -- If possible, transfer amount from source to target. do if source.balance >= amount then source.withdraw (amount) target.deposit (amount) end end Typical calls: transfer (acc1, acc2, 100) transfer (acc1, acc3, 100)
  • 29. A better SCOOP version transfer (source, target: separate ACCOUNT; amount: INTEGER) -- Transfer amount from source to target. require source.balance >= amount do source.withdraw (amount) target.deposit (amount) ensure source.balance = old source.balance – amount target.balance = old target.balance + amount end
  • 30. Dining Philosophers • find out about it…
  • 32. Sequential Programming • Used to be messy • Still hard but key improvements: • Structured programming • Data abstraction & object technology • Design by Contract • Genericity, multiple inheritance • Architectural techniques
  • 33. Concurrent Programming • Used to be messy • Example: threading models in most popular approaches • Development level: sixties/seventies • Only understandable through operational reasoning
  • 34. References • http://www.javaworld.com/article/2078679/java-concurrency/java-concurrency-modern- threading-for-not-quite-beginners.html • https://books.google.mv/books?id=- x1S4neCSOYC&pg=PA5&lpg=PA5&dq=what+is+using+concurrency+constructs&source=bl&ot s=Dxdk47Ddy- &sig=ZxzRD163royyROmEOF2lAtSZBz8&hl=en&sa=X&ved=0CEkQ6AEwBmoVChMIx- rc1ZbYxwIVQQeOCh3LkguH#v=onepage&q=what%20is%20using%20concurrency%20constru cts&f=false • http://book.realworldhaskell.org/read/concurrent-and-multicore-programming.html • https://books.google.mv/books?id=mHozgJ7ngq0C&pg=PA1&lpg=PA1&dq=what+is+using+con currency+constructs&source=bl&ots=TOT_g- IESw&sig=xSG7JzGquRD9NZmnbkt6tv6Vr2A&hl=en&sa=X&ved=0CFcQ6AEwCWoVChMIx- rc1ZbYxwIVQQeOCh3LkguH#v=onepage&q=what%20is%20using%20concurrency%20constru cts&f=false • http://gee.cs.oswego.edu/dl/cpj/mechanics.html • Read stack overflow / java documentation / etc
  • 35. Next Up… • Concurrent Programming… Sachintha Gunasena MBCS http://lk.linkedin.com/in/sachinthadtg
  • 36. Thank you. Sachintha Gunasena MBCS http://lk.linkedin.com/in/sachinthadtg