Lecture on Java Concurrency Day 2 on Feb 4, 2009.


Published on

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.html

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Lecture on Java Concurrency Day 2 on Feb 4, 2009.

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