Class ExecutorSubmitter

java.lang.Object
com.gruelbox.transactionoutbox.ExecutorSubmitter
All Implemented Interfaces:
Submitter

public class ExecutorSubmitter extends Object implements Submitter
Schedules background work using a local Executor implementation. Note that the Runnables submitted to this will not be Serializable so will not be suitable for remoting. Remote submission of work is not yet supported.

Note that there are some important aspects that should be considered in the configuration of this executor:

  • Should use a BOUNDED blocking queue implementation such as ArrayBlockingQueue, otherwise under high volume, the queue may get so large it causes out-of-memory errors.
  • Should use a RejectedExecutionHandler which either throws (such as ThreadPoolExecutor.AbortPolicy), silently fails (such as ThreadPoolExecutor.DiscardPolicy) or blocks the calling thread until a thread is available. It should not execute the work in the calling thread (e.g. ThreadPoolExecutor.CallerRunsPolicy, since this could result in unpredictable effects with tasks assuming they will be run in a different thread context corrupting thread state. Generally, throwing or silently failing are preferred since this allows the database to absorb all backpressure, but if you have a strong reason to choose a blocking policy to enforce upstream backpressure, be aware that TransactionOutbox.flush() can potentially block for a long period of time too, so design any background processing which calls it accordingly (e.g. avoid calling from a timed scheduled job; perhaps instead simply loop it).
  • The queue can afford to be quite large in most realistic production deployments, and it is advised that it be so (10000+).