Date post: | 13-Dec-2014 |
Category: |
Technology |
Upload: | kyung-koo-yoon |
View: | 343 times |
Download: | 0 times |
Practical Concurrency
January, 2009
http://javadom.blogspot.com/2011/06/lecture-on-java-concurrency-day-2.html
Day 2 (9am, Feb 4, 2009)
Concurrency ConcernsPerformanceConcurrency Design
2-1 Concurrency Concerns
CorrectnessLiveness
Correctness (Multi-threaded Safety)
Conflicts Read-write conflicts Write-write conflicts
Liveness
Blockages Lock Wait Input CPU contention Failure
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
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
2-2 Performance
Amdahl’s lawContext Switch OverheadMemory Barrier Overhead
Amdahl’s law
Context Switch Overhead
All the Registers Program Control Block
Kernel stack User Area
Text/data/stack
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
2-3 Concurrency Design
Concurrency Design StepConcernsObjects in Worker Thread ModelCollection Design
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
Concerns on Designing Concurrency
Liveness Deadlock Starvation Waiting
Performance Context switching overhead Lock contention
Further considerations
Thread confinement Locking itself is not critical overhead
Lock contention and context switching is.
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
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
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