lecture on java concurrency day 2 on feb 4, 2009
DESCRIPTION
Lecture on Java Concurrency Day 2 on Feb 4, 2009. (in Korean)Lectures are 4 days in all.See http://javadom.blogspot.com/2011/06/lecture-on-java-concurrency-day-2.htmlTRANSCRIPT
![Page 1: Lecture on Java Concurrency Day 2 on Feb 4, 2009](https://reader036.vdocuments.site/reader036/viewer/2022082700/548bf766b479599f408b4651/html5/thumbnails/1.jpg)
Practical Concurrency
January, 2009
http://javadom.blogspot.com/2011/06/lecture-on-java-concurrency-day-2.html
![Page 2: Lecture on Java Concurrency Day 2 on Feb 4, 2009](https://reader036.vdocuments.site/reader036/viewer/2022082700/548bf766b479599f408b4651/html5/thumbnails/2.jpg)
Day 2 (9am, Feb 4, 2009)
Concurrency ConcernsPerformanceConcurrency Design
![Page 3: Lecture on Java Concurrency Day 2 on Feb 4, 2009](https://reader036.vdocuments.site/reader036/viewer/2022082700/548bf766b479599f408b4651/html5/thumbnails/3.jpg)
2-1 Concurrency Concerns
CorrectnessLiveness
![Page 4: Lecture on Java Concurrency Day 2 on Feb 4, 2009](https://reader036.vdocuments.site/reader036/viewer/2022082700/548bf766b479599f408b4651/html5/thumbnails/4.jpg)
Correctness (Multi-threaded Safety)
Conflicts Read-write conflicts Write-write conflicts
![Page 5: Lecture on Java Concurrency Day 2 on Feb 4, 2009](https://reader036.vdocuments.site/reader036/viewer/2022082700/548bf766b479599f408b4651/html5/thumbnails/5.jpg)
Liveness
Blockages Lock Wait Input CPU contention Failure
![Page 6: Lecture on Java Concurrency Day 2 on Feb 4, 2009](https://reader036.vdocuments.site/reader036/viewer/2022082700/548bf766b479599f408b4651/html5/thumbnails/6.jpg)
Deadlock
A situation wherein two or more competing actions are waiting for the other to finish, and thus neither ever does. Lock-ordering deadlock Dynamic lock-ordering deadlock Resource deadlock Thread-starvation deadlock
![Page 7: Lecture on Java Concurrency Day 2 on Feb 4, 2009](https://reader036.vdocuments.site/reader036/viewer/2022082700/548bf766b479599f408b4651/html5/thumbnails/7.jpg)
Livelock
similar to a deadlock, except that the states of the processes involved in the livelock constantly change with regard to one another, none progressing
![Page 8: Lecture on Java Concurrency Day 2 on Feb 4, 2009](https://reader036.vdocuments.site/reader036/viewer/2022082700/548bf766b479599f408b4651/html5/thumbnails/8.jpg)
2-2 Performance
Amdahl’s lawContext Switch OverheadMemory Barrier Overhead
![Page 9: Lecture on Java Concurrency Day 2 on Feb 4, 2009](https://reader036.vdocuments.site/reader036/viewer/2022082700/548bf766b479599f408b4651/html5/thumbnails/9.jpg)
Amdahl’s law
![Page 10: Lecture on Java Concurrency Day 2 on Feb 4, 2009](https://reader036.vdocuments.site/reader036/viewer/2022082700/548bf766b479599f408b4651/html5/thumbnails/10.jpg)
Context Switch Overhead
All the Registers Program Control Block
Kernel stack User Area
Text/data/stack
![Page 11: Lecture on Java Concurrency Day 2 on Feb 4, 2009](https://reader036.vdocuments.site/reader036/viewer/2022082700/548bf766b479599f408b4651/html5/thumbnails/11.jpg)
Memory Barrier a class of instructions which cause a
central processing unit (CPU) to enforce an ordering constraint on memory operations issued before and after the barrier instruction.
Assures ordered access and memory visibility in multi-processor environments
Accessing volatile fields are usually implemented using memory barrier
![Page 12: Lecture on Java Concurrency Day 2 on Feb 4, 2009](https://reader036.vdocuments.site/reader036/viewer/2022082700/548bf766b479599f408b4651/html5/thumbnails/12.jpg)
2-3 Concurrency Design
Concurrency Design StepConcernsObjects in Worker Thread ModelCollection Design
![Page 13: Lecture on Java Concurrency Day 2 on Feb 4, 2009](https://reader036.vdocuments.site/reader036/viewer/2022082700/548bf766b479599f408b4651/html5/thumbnails/13.jpg)
Steps of Designing Concurrency
1. Identify Shared Resources2. Identify Critical Sections3. Design Lock Granularity4. Check multiple locking sanity
1. Check long critical sections2. Check possible locking order problems
![Page 14: Lecture on Java Concurrency Day 2 on Feb 4, 2009](https://reader036.vdocuments.site/reader036/viewer/2022082700/548bf766b479599f408b4651/html5/thumbnails/14.jpg)
Concerns on Designing Concurrency
Liveness Deadlock Starvation Waiting
Performance Context switching overhead Lock contention
![Page 15: Lecture on Java Concurrency Day 2 on Feb 4, 2009](https://reader036.vdocuments.site/reader036/viewer/2022082700/548bf766b479599f408b4651/html5/thumbnails/15.jpg)
Further considerations
Thread confinement Locking itself is not critical overhead
Lock contention and context switching is.
![Page 16: Lecture on Java Concurrency Day 2 on Feb 4, 2009](https://reader036.vdocuments.site/reader036/viewer/2022082700/548bf766b479599f408b4651/html5/thumbnails/16.jpg)
Worker Threads
Worker threads One thread to execute many unrelated
tasks Aka., background threads or thread pools
(when more than one thread is used) Object life cycle and work threads
Instance sharing New instance per work
Worker threads and Instance variables
![Page 17: Lecture on Java Concurrency Day 2 on Feb 4, 2009](https://reader036.vdocuments.site/reader036/viewer/2022082700/548bf766b479599f408b4651/html5/thumbnails/17.jpg)
Worker Threads and Objects JavaEE EJB Session Bean
Stateless session bean objects are pooled The container assures the serialized access
to each objects (so, always thread-safe) Statefull session bean might throw
ConcurrentAccessException JavaEE Servlet
Servlet object life cycle Objects per
Request/Session/Page/Application lifecycle
![Page 18: Lecture on Java Concurrency Day 2 on Feb 4, 2009](https://reader036.vdocuments.site/reader036/viewer/2022082700/548bf766b479599f408b4651/html5/thumbnails/18.jpg)
Worker Threads and Objects (2) JMX MBean (Local/Connector)
Creates new thread per messages Just like the servlet model
ProBus Process(or Flow) Use the same Flow class and LProcess objects
are created per flow instances (contentions against Lprocess and …)
BizMaster Workflow Process Per-process class is generated and no process
instances (contentions against RuntimeContext and …)
ProBus Adapter Rule Just like the servlet model