Java Concurrency
Java Concurrency
Java Concurrency
DELIVERY METHODS
COURSE OVERVIEW
Public (classroom and virtual) This course provides thorough coverage of the
Private, onsite concurrency related aspects of Java platform. This is an
advanced course targeted at experienced Java
COURSE DURATION programmers. Starting off with intermediated level, this
course covers some of the most powerful and cutting
Three days, instructor-led training edge Java concurrency concepts. Driven through a
series of pedagogically designed hands-on exercises, all
TARGET AUDIENCE the new concepts learnt would be applied immediately
Experienced Java developers who want to understand
Java Concurrency and Threads with hands-on
experience and a focus on understanding the
underlying concepts.
PREREQUISITES
1. Thread Basics
Thread class and Runnable interface
Thread States 5. Inter-Thread Communication & Dead Locks
Liveliness concept
Starting Threads
Concept of DeadLock
Thread API for Thread management
Causes of DeadLocks
Sleep, Join etc
Lock-ordering deadlocks
Strategies for stopping threads
Dynamic lock order deadlocks
Interrupt Flag
Deadlock between cooperating objects
Interrupted(),interrupt(),isInterrupted()
Lock Contention
Using Object's wait() & notify() mechanism
A Producer/Consumer problem
2. Synchronization and Thread Safety
Problems with Sharing Data Live Locks - Causes and Example
Race Conditions
'synchronized' keyword
Synchronization for creating Mutexes 6. Explicit Locking and Conditions
Why?
Monitor concept and synchronized blocks
Lock and ReentrantLock
Common misconceptions about 'synchronized'
Memory visibility semantics
ReentrantLock implementation
Using the explicit lock
Using try-finally
3. Synchronization Internals
Reordering and Visibility tryLock and timed locks
Volatile keyword Using try-lock to avoid deadlocks
Idea of 'Happens Before' Interruptible locking
Atomicity Concept Synchronized vs ReentrantLock
Atomic Types in java.util.atomic Memory semantics
Synchronization vs. Volatile vs. Atomic comparison Ease of use
Prefer synchronized
Condition Interface and Creating multiple conditions
4. Designing for Thread Safety Read-write locks
Encapsulation in the light of Thread Safety
ReadWriteLock interface
Primitive vs object fields
Understanding system to avoid starvation
Object Immutability
StampedLock (Java 8)
Idea of Leak / Escape
Difference between StampedLock and
Safe Publication
ReentrantReadWriteLock
ThreadLocal class and its uses
Pessimistic reading and writing
Optimistic reading
Conditional changes by upgrading read to write lock
Performance differences between StampedLock and
ReentrantReadWriteLock
Java Concurrency
7. Thread Safe and Concurrent Collections 9. High Level Concurrency Utilities (Synchronizers)
Synchronized collections Use Cases and Examples of using :
Old Java 1.0 thread-safe containers CountDownLatch
Synchronized wrapper classes Semaphore
Locking with compound actions CyclicBarrier
Concurrent collections Phaser (Java 7)
Scalability
ConcurrentHashMap
New Java 8 methods 10. Task Execution Framework
Executor interface
Additional atomic operations
Motivation for using Executor
Java 8 ConcurrentHashMap
Decoupling task submission from execution
CopyOnWriteCollections
Execution policies
Blocking queues and the producer-consumer pattern
Who will execute it?
How BlockingQueues work
In which order? (FIFO, LIFO, by priority)
Java implementations of BlockingQueue
Various sizing options for number of threads and queue
ArrayBlockingQueue
length
Circular array lists
Executor lifecycle, state machine
LinkedBlockingQueue
Shutdown() vs ShutdownNow()
PriorityBlockingQueue
Callable and Future
DelayQueue
Future details
SynchronousQueue
CompletionService
TransferQueue
Intro to CompletableFuture (Java 8)
Deques
Time limited tasks
ArrayDeque
Cancellation
LinkedBlockingDeque
Cooperative vs preemptive cancellation
ConcurrentLinkedDeque (Java 7)
Using flags to signal cancellation
Cancellation policies
Interruption
8. Using Parallel Streams (Java 8)
Transforming collections into streams Responding to interruption
Limitations of using parallel streams for IO
Finding prime numbers in parallel
Filtering and mapping streams
Configuring underlying Fork/Join framework
Java Concurrency