Return to Homegeneral info-bulletjavadashsybase-technical training-instructors
training - java courses - advanced java courses


Advanced Multithreading in Java

Java's powerful, built-in multithreading capabilities make multithreading accessible to programmers in an easy-to-use manner. Unfortunately, it also makes the subtle issues and errors that multithreaded programs are prone to more accessible. This module covers the more complex multithreading features of Java that are not covered in the typical Introduction to Java course, and points out some of the pitfalls, strategies, and tradeoffs that should be considered.

 

Topics include:
Brief review of multithreading in Java
What are threads
Class thread
Interface runnable
The Java thread scheduler
Thread priorities
Platform specific issues
The thread lifecycle
State net for threads
Creating threads
Controlling threads
ThreadGroups
Race conditions
Data synchronization
Synchronized methods
Synchronized blocks
Synchronization costs
Strategies for safety
Immutable objects

Full synchronization
Partial synchronization - Critical sections and  invariants
Contained objects
Deadlock
Deadlock prevention - strategies for liveness
Liveness failures
Liveness vs. safety
Top-down design (safety first)
Bottom-up design (liveness first)
Instance variable analysis - accessors and  updates
Removing synchronization
Signaling using wait, notify, notifyall
The Producer/Consumer pattern
Avoiding starvation
Wait sets, locks, and monitors
The nested monitor problem
The Java daemon threads

 

Lab Exercises
Review of basic multithreading
Creating Threads
Implementing Runnable
Costs of synchronization - Timing synchronized and unsynchronized method calls.

 
Bank Exercise Series
This lab series explores the problems that race conditions and unsynchronized multithreading cause by simulating multiple Java synchronization mechanisms. It also gives examples of threaded utility classes such as CountDownTimer - a Thread that "wakes up" an object at specified intervals.

The labs include:
Creating the bank simulation
Observing problems with unsynchronized data access.
Adding synchronization
Ensuring correct behavior with wait and notify.

 
Bakery Simulation Series
This lab series explores the issues to be considered when using a multithreaded Producer/Consumer model, and illustrates solutions using wait and join.

The labs include:
Creating the bakery simulation.
Observing the problems of uncontrolled production or consumption
Making it work right using wait and notify.

 

|   return to top   |