Java SE Concurrency - High-Level

Print the objectives

Take the exam   Take a beta test

Java is one of the few languages designed from inception to support concurrency without the requirement for additional libraries. Tools for the management of concurrent programming have been available from the very first releases of the language, providing both syntactic and API support.

Until the release of Java 1.5, these tools have been powerful but primitive, a developer having the facilities to synchronize on monitors at a class, instance and nominated Object level, combined with the functionality provided by Object, Thread, ThreadGroup and ThreadLocal classes.

With the advent these packages in the Java 1.5 release:
  • java.util.concurrent
  • java.util.concurrent.atomic
  • java.util.concurrent.locks
A whole host of extended facilities have been added to the Java API allowing far finer grained control over concurrent programming tasks.

This examination will seek to test the examinee's knowledge of the high-level concepts of concurrent programming, and higher-level aspects of both the pre 1.5 API toolset, and the new Java 1.5 API additions.

Although the synchronized keyword and the Object.wait(), notify() and notifyAll() methods are considered low-level, as their usage is so prevalent in existing code bases, an exception has been made and thus they are included in this high-level exam.

Notes:
  1. This exam does not cover the areas covered in the Java SE Concurrency - Low-Level exam.
  2. The exam objectives and questions are written for Java 1.5 API release.
  Released  Beta  Frozen  

Concepts & Terminology

Be able to explain what concurrent programming is, what it is used for, and the meanings of the associated terminology.
 
 

Terminology  2 questions

Be able to define the following terms:
  • Concurrent
  • Synchronized
  • Monitor
  • Contention
  • Thread
  • Producer/Consumer
5 55 25

Behaviours  1 question

Explain the distinctions between:
  • Blocking execution and Non-Blocking execution
  • Concurrent code and Synchronized code
1 14 6

Synchronized, wait and notify

 
 

Monitor identification  1 question

Describe synchronization, and be able to identify which object is supplying the implicit monitor for synchronization in each case:
  • The class: static methods. Examples:
public static synchronized void x() { ... }
  • The instantiated object: Synchronized instance methods. Example:
public synchronized void y() { ... }
  • A nominated Object: Manually synchronized blocks. Example:
synchronized(z) { ... }
1 62 9

Synchronization behaviour  1 question

Describe the behaviour of the following methods:
  • Object.wait();
  • Object.notify();
  • Object.notifyAll();

And with regard to these methods:
  • Understand the need for synchronization prior to calling any of these methods.
  • Predict the re-entrant behaviour of threads within synchronized sections.
  • Explain that there is no guarantee regarding the order of waiting threads receiving a notification.
4 78 6

Interfaces & Enums  2 questions

Define the responsibilities and uses of the following interfaces
  • Runnable and Callable (and know the differences)
  • Executor
  • Future
  • TimeUnit
4 17 12

Implementations

 
 

Threads & ThreadGroups  2 questions

Be able to write a running Thread by either:
  • Extending Thread and calling start(), or,
  • Implementing Runnable, and calling new Thread(Runnable).start().
List the advantages and disadvantages of each of the two options. Explain how Threads relate to ThreadGroups, and why ThreadGroup usage is discouraged.
2 72 18

Executors factory  2 questions

Explain the usage of the Executors factory to create the following ExecutorService implementations:
  • A default thread factory,
  • A cached thread pool,
  • A fixed thread pool,
  • A scheduled thread pool,
  • A single thread executor, and,
  • A single thread scheduled executor
Be able to explain the behaviour of these ExecutorServices, and be able to select the correct ExecutorService from those available from the factory for a given well defined problem.
1 10 10

Monitoring tasks  2 questions

In order to use the ExecutorService implementations, show how to correctly implement and use:
  • Callable
  • Future
2 12 9

Task management  2 questions

Understand the responsibilities of the following interfaces
  • ExecutorService
    • Write viable code to submit new jobs for processing, using submit, invokeAll and invokeAny.
    • Explain the principles of shutting down the service using either shutdown or shutdownNow
    • Identify the methods used to monitor the progress of a shutdown.
  • ScheduledExecutorService
    • Explain how to submit a new job for:
      • Processing after a specified delay using schedule().
      • Repeated processing with a fixed delay between the start of each run using scheduleAtFixedRate().
      • Repeated processing with a fixed delay between the end of one run and the start of the next using scheduleWithFixedDelay().
    • Demonstrate how to cancel the scheduled job using the cancel() method on the ScheduledFuture returned by the schedule*() methods.
4 8 8

Collections

Covering the less complex concurrent collections extensions
 
 

Maps  2 questions

  • Explain the function of the ConcurrentMap interface & ConcurrentHashMap class
  • Display proper usage of the methods:
    • putIfAbsent(K, V),
    • remove(Object, Object),
    • replace(K, V), and
    • replace(K, V, V)
2 5 9

Queues  3 questions

  • BlockingQueue implementations, and their distinguishing characteristics:
    • Distinguish from the original Queue defined in the Collections framework.
    • Define the behaviour of the add(), offer() and put() methods, and what distinguishes them.
    • Explain the behaviour of the take(), peek() and poll() methods, and what distinguishes them.
  • ArrayBlockingQueue
    • Show that the array backing the queue is fixed at construction and once bounded cannot be changed.
    • Predict the behaviour when
      • Attempting to put into a full queue, or
      • Attempting to take from an empty queue will block.
  • LinkedBlockingQueue
    • Write code to construct a LinkedBlockingQueue with:
      • limited capacity, or
      • undefined capacity, being able to identify the default capacity.
    • Demonstrate that the iterator() method will:
      • return a weakly consistent iterator, and explain what weak consistency is, and
      • return an iterator that not subject to throwing ConcurrentModificationExceptions.
    • Know which method to call to determine the remaining capacity of the queue, and know that this is an ideal value, not allowing for resource constraints.
5 11 12

Iterators  1 question

Identify the changes to the concurrent Iterator implementations:
  • No longer throwing ConcurrentModificationExceptions
  • Weak references to underlying data
  • Know that the data is guaranteed to be right at time of creation, but not at any later time.
4 3 4

Synchronizers

Detail the behaviour of two of the new synchronizer implementations, how to use them, and how they differ
 
 

Semaphore  2 questions

  • Explain what permits are, and how a single permit makes a binary semaphore.
  • Write code to instantiate a Semaphore.
  • The behaviour of acquire(), acquireUninterruptibly() and tryAcquire().
  • Grasp that a Thread calling release() does not need to have ever acquired a permit.
  • Identify methods to use to determine if there are blocked threads, what their count is, and get a reference to their instances.
  • Write code to synchronize multiple threads using a Semaphore.
3 12 13

CountDownLatch  2 questions

  • Show that this class is limited to a single usage.
  • Write code to instantiate CountDownLatch, and explain the significance of the count parameter.
  • Explain the behaviour of the await() method.
  • Explain the behaviour of the countDown() method.
  • Identify the method to query the outstanding count.
  • Show suspension of one or more threads, awaiting one or more other threads reaching an arbitrary point using CountDownLatch to communicate.
5 5 6

Exam information

  • 37 minutes
  • 25 questions (554)
  • 80% required
  • +3 √
  • - 12  points
  • 15 day delay
  • status: released

Exam leader