SlideShare a Scribd company logo
1 of 36
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

What's hot

Java New Evolution
Java New EvolutionJava New Evolution
Java New EvolutionAllan Huang
 
Concurrency Programming in Java - 06 - Thread Synchronization, Liveness, Guar...
Concurrency Programming in Java - 06 - Thread Synchronization, Liveness, Guar...Concurrency Programming in Java - 06 - Thread Synchronization, Liveness, Guar...
Concurrency Programming in Java - 06 - Thread Synchronization, Liveness, Guar...Sachintha Gunasena
 
Multithreading 101
Multithreading 101Multithreading 101
Multithreading 101Tim Penhey
 
.NET: Thread Synchronization Constructs
.NET: Thread Synchronization Constructs.NET: Thread Synchronization Constructs
.NET: Thread Synchronization ConstructsSasha Kravchuk
 
.NET Multithreading/Multitasking
.NET Multithreading/Multitasking.NET Multithreading/Multitasking
.NET Multithreading/MultitaskingSasha Kravchuk
 
Java Multithreading Using Executors Framework
Java Multithreading Using Executors FrameworkJava Multithreading Using Executors Framework
Java Multithreading Using Executors FrameworkArun Mehra
 
Concurrency with java
Concurrency with javaConcurrency with java
Concurrency with javaHoang Nguyen
 
Multithreading
MultithreadingMultithreading
MultithreadingF K
 

What's hot (15)

Java New Evolution
Java New EvolutionJava New Evolution
Java New Evolution
 
Concurrency Programming in Java - 06 - Thread Synchronization, Liveness, Guar...
Concurrency Programming in Java - 06 - Thread Synchronization, Liveness, Guar...Concurrency Programming in Java - 06 - Thread Synchronization, Liveness, Guar...
Concurrency Programming in Java - 06 - Thread Synchronization, Liveness, Guar...
 
Multi-Threading
Multi-ThreadingMulti-Threading
Multi-Threading
 
Multithreading 101
Multithreading 101Multithreading 101
Multithreading 101
 
.NET: Thread Synchronization Constructs
.NET: Thread Synchronization Constructs.NET: Thread Synchronization Constructs
.NET: Thread Synchronization Constructs
 
.NET Multithreading/Multitasking
.NET Multithreading/Multitasking.NET Multithreading/Multitasking
.NET Multithreading/Multitasking
 
gcdtmp
gcdtmpgcdtmp
gcdtmp
 
Threading in C#
Threading in C#Threading in C#
Threading in C#
 
multithreading
multithreadingmultithreading
multithreading
 
Java Multithreading Using Executors Framework
Java Multithreading Using Executors FrameworkJava Multithreading Using Executors Framework
Java Multithreading Using Executors Framework
 
Concurrency with java
Concurrency with javaConcurrency with java
Concurrency with java
 
Java
JavaJava
Java
 
Java Memory Model
Java Memory ModelJava Memory Model
Java Memory Model
 
Java
JavaJava
Java
 
Multithreading
MultithreadingMultithreading
Multithreading
 

Similar to Concurrency Programming in Java - 01 - Introduction to Concurrency Programming

Coding For Cores - C# Way
Coding For Cores - C# WayCoding For Cores - C# Way
Coding For Cores - C# WayBishnu Rawal
 
VTU 6th Sem Elective CSE - Module 3 cloud computing
VTU 6th Sem Elective CSE - Module 3 cloud computingVTU 6th Sem Elective CSE - Module 3 cloud computing
VTU 6th Sem Elective CSE - Module 3 cloud computingSachin Gowda
 
Multicore_Architecture Book.pdf
Multicore_Architecture Book.pdfMulticore_Architecture Book.pdf
Multicore_Architecture Book.pdfSwatantraPrakash5
 
Parallel Computing-Part-1.pptx
Parallel Computing-Part-1.pptxParallel Computing-Part-1.pptx
Parallel Computing-Part-1.pptxkrnaween
 
Parallel architecture &programming
Parallel architecture &programmingParallel architecture &programming
Parallel architecture &programmingIsmail El Gayar
 
Data Parallel and Object Oriented Model
Data Parallel and Object Oriented ModelData Parallel and Object Oriented Model
Data Parallel and Object Oriented ModelNikhil Sharma
 
Parallel architecture-programming
Parallel architecture-programmingParallel architecture-programming
Parallel architecture-programmingShaveta Banda
 
Research Scope in Parallel Computing And Parallel Programming
Research Scope in Parallel Computing And Parallel ProgrammingResearch Scope in Parallel Computing And Parallel Programming
Research Scope in Parallel Computing And Parallel ProgrammingShitalkumar Sukhdeve
 
Chap 2 classification of parralel architecture and introduction to parllel p...
Chap 2  classification of parralel architecture and introduction to parllel p...Chap 2  classification of parralel architecture and introduction to parllel p...
Chap 2 classification of parralel architecture and introduction to parllel p...Malobe Lottin Cyrille Marcel
 
Week # 1.pdf
Week # 1.pdfWeek # 1.pdf
Week # 1.pdfgiddy5
 
Programming language paradigms
Programming language paradigmsProgramming language paradigms
Programming language paradigmsAshok Raj
 
5.7 Parallel Processing - Reactive Programming.pdf.pptx
5.7 Parallel Processing - Reactive Programming.pdf.pptx5.7 Parallel Processing - Reactive Programming.pdf.pptx
5.7 Parallel Processing - Reactive Programming.pdf.pptxMohamedBilal73
 
Lec 2 (parallel design and programming)
Lec 2 (parallel design and programming)Lec 2 (parallel design and programming)
Lec 2 (parallel design and programming)Sudarshan Mondal
 
Parallel Computing - Lec 5
Parallel Computing - Lec 5Parallel Computing - Lec 5
Parallel Computing - Lec 5Shah Zaib
 
.net Based Component Technologies
.net Based Component Technologies.net Based Component Technologies
.net Based Component Technologiesprakashk453625
 
object oriented programming examples
object oriented programming examplesobject oriented programming examples
object oriented programming examplesAbdii Rashid
 
6-9-2017-slides-vFinal.pptx
6-9-2017-slides-vFinal.pptx6-9-2017-slides-vFinal.pptx
6-9-2017-slides-vFinal.pptxSimRelokasi2
 
Introduction to OpenSees by Frank McKenna
Introduction to OpenSees by Frank McKennaIntroduction to OpenSees by Frank McKenna
Introduction to OpenSees by Frank McKennaopenseesdays
 

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

Coding For Cores - C# Way
Coding For Cores - C# WayCoding For Cores - C# Way
Coding For Cores - C# Way
 
VTU 6th Sem Elective CSE - Module 3 cloud computing
VTU 6th Sem Elective CSE - Module 3 cloud computingVTU 6th Sem Elective CSE - Module 3 cloud computing
VTU 6th Sem Elective CSE - Module 3 cloud computing
 
Multicore_Architecture Book.pdf
Multicore_Architecture Book.pdfMulticore_Architecture Book.pdf
Multicore_Architecture Book.pdf
 
Parallel Computing-Part-1.pptx
Parallel Computing-Part-1.pptxParallel Computing-Part-1.pptx
Parallel Computing-Part-1.pptx
 
Parallel architecture &programming
Parallel architecture &programmingParallel architecture &programming
Parallel architecture &programming
 
Cc module 3.pptx
Cc module 3.pptxCc module 3.pptx
Cc module 3.pptx
 
Data Parallel and Object Oriented Model
Data Parallel and Object Oriented ModelData Parallel and Object Oriented Model
Data Parallel and Object Oriented Model
 
Parallel architecture-programming
Parallel architecture-programmingParallel architecture-programming
Parallel architecture-programming
 
Research Scope in Parallel Computing And Parallel Programming
Research Scope in Parallel Computing And Parallel ProgrammingResearch Scope in Parallel Computing And Parallel Programming
Research Scope in Parallel Computing And Parallel Programming
 
Chap 2 classification of parralel architecture and introduction to parllel p...
Chap 2  classification of parralel architecture and introduction to parllel p...Chap 2  classification of parralel architecture and introduction to parllel p...
Chap 2 classification of parralel architecture and introduction to parllel p...
 
Week # 1.pdf
Week # 1.pdfWeek # 1.pdf
Week # 1.pdf
 
Programming language paradigms
Programming language paradigmsProgramming language paradigms
Programming language paradigms
 
5.7 Parallel Processing - Reactive Programming.pdf.pptx
5.7 Parallel Processing - Reactive Programming.pdf.pptx5.7 Parallel Processing - Reactive Programming.pdf.pptx
5.7 Parallel Processing - Reactive Programming.pdf.pptx
 
Lec 2 (parallel design and programming)
Lec 2 (parallel design and programming)Lec 2 (parallel design and programming)
Lec 2 (parallel design and programming)
 
Parallel Computing - Lec 5
Parallel Computing - Lec 5Parallel Computing - Lec 5
Parallel Computing - Lec 5
 
.net Based Component Technologies
.net Based Component Technologies.net Based Component Technologies
.net Based Component Technologies
 
Oop.pptx
Oop.pptxOop.pptx
Oop.pptx
 
object oriented programming examples
object oriented programming examplesobject oriented programming examples
object oriented programming examples
 
6-9-2017-slides-vFinal.pptx
6-9-2017-slides-vFinal.pptx6-9-2017-slides-vFinal.pptx
6-9-2017-slides-vFinal.pptx
 
Introduction to OpenSees by Frank McKenna
Introduction to OpenSees by Frank McKennaIntroduction to OpenSees by Frank McKenna
Introduction to OpenSees by Frank McKenna
 

More from Sachintha Gunasena

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

More from Sachintha Gunasena (16)

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

Recently uploaded

Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfkalichargn70th171
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 

Recently uploaded (20)

Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Odoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting ServiceOdoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting Service
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 

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