Skip navigation links

Package xal.tools.dispatch

The dispatch package is an attempted Java port of some of the functionality of the open source libdispatch library.

See: Description

Package xal.tools.dispatch Description

The dispatch package is an attempted Java port of some of the functionality of the open source libdispatch library. Only some of the basic functions have been implemented. This implementation provides compatibility with the libdispatch library within the context of Java. Due to limitations of Java, there is no way to determine the optimal number of operations to schedule concurrently. Since Java has no equivalent of C Blocks, there is additional overhead in dispatching operations.

Motivation

The motivation for this package is to provide a corresponding implementation for many functions in libdispatch to ease the portability of programs between C and Java. Furthermore, this package addresses several shortcomings of the java.util.concurrent package:
  • Consistent API which includes access to the Swing thread.
  • Support for barrier operations.
  • Groups for synchronizing operations.
  • Support for iteration operations evaluated concurrently.
  • Simple API for getting the value from a synchronous call without having to deal with a Future.

Common Examples

Snippet Description
DispatchQueue queue = DispatchQueue.createConcurrentQueue( "Demo Concurrent" ) Create a new concurrent dispatch queue.
DispatchQueue queue = DispatchQueue.createSerialQueue( "Demo Serial" ) Create a new serial dispatch queue.
DispatchQueue queue = DispatchQueue.getGlobalDefaultPriorityQueue() Get the global dispatch queue with default priority.
DispatchQueue queue = DispatchQueue.getMainQueue() Get the main dispatch queue (schedules on the Swing thread).
queue.dispatchAsync( runnableOperation ) Submit the operation to the queue without waiting for it to complete.
queue.dispatchAfter( time, runnableOperation ) Submit the operation to the queue after the specified time without waiting for it to complete.
queue.dispatchSync( runnableOperation ) Submit the operation to the queue and wait for it to complete.
queue.dispatchSync( callableOperation ) Submit the operation to the queue, wait for it to complete and return the result.
queue.dispatchBarrierAsync( runnableOperation ) Submit the operation to the queue without waiting for it to complete. The barrier operation will not execute until all operations ahead of it in the queue complete. No other operation will execute concurrently with the barrier operation on the same queue. Operations after the barrier in the queue will execute after the barrier completes.
queue.dispatchBarrierSync( runnableOperation ) Submit the operation to the queue and wait for it to complete. The barrier operation will not execute until all operations ahead of it in the queue complete. No other operation will execute concurrently with the barrier operation on the same queue. Operations after the barrier in the queue will execute after the barrier completes.
DispatchGroup group = new DispatchGroup() Create a new dispatch group.
group.enter() Add any operations to the group which are subsequently dispatched.
group.leave() Stop adding operations to the group.
queue.dispatchAsync( group, runnableOperation ) Convenience method to submit the operation to the queue without waiting for it to complete and add the operation to the group.
group.waitForCompletion() Wait until all operations associated with the group have completed.
Skip navigation links