This directory contains a number of separate examples. These have no external dependencies, but may require multiple classes from within the directory. These examples should be used with Java 11+.
These examples may be loaded and run in an IDE at the Ch06 level. You may
need to set the project JDK version.
accounts/Main.java- Example of a concurrent account transfer system. Uses other classes from in theaccountsdirectory.CDLExamples.java- Example usage of theCountDownLatchclassCFExamples.java- Example usage of theCompletableFutureclassCOWExamples.java- Exampe usage of theCopyOnWriteArrayListclassExecutorExamples.java- Example usage of theExecutors.newSingleThreadExecutorfactory methodFutureExamples.java- Example usage of theFuture<>interfaceRWLockExamples.java- Example usage of theReentrantReadWriteLockclass
Several examples explore issues around concurrent access to Map implementations
BadMapExamples.java- Example of bad results from unsafe concurrent access toHashMap.Dictionary.java- A basic, non-concurrent implementation of theMapinterface.ImmutableDictionary.java- An immutable wrapper around ourDictionaryclass.SynchronizedDictionary.java- A naively synchronized wrapper around ourDictionaryclass.
To compile and run these samples at the command-line, do the following:
cd Ch06/ch06
javac *.java
java -cp .. ch06.BadMapExamples
cd Ch06/ch06/accounts
javac *.java
java cp ../.. ch06.accounts.Main