Creating Background Processes

To create a background process, there are three important classes that need to be created.

  • An implementation of com.splwg.base.api.batch.BatchJob. This is the "driver" and should:
    • Include a "BatchJob" class annotation
    • Extend a generated superclass. In the case where the batch job is named "Foo", the generated superclass will be "Foo_​Gen".
  • An implementation of com.splwg.base.api.batch.ThreadWorker. This is responsible for processing the work distributed to a processing thread. By convention, this is coded as a static inner class within the BatchJob class implementation described above. If the file becomes excessively large, the worker can be split into its own source file. The worker class extends a generated abstract superclass. In the case of the "Foo" batch job, the worker should be named FooWorker and extend "FooWorker_​Gen".
  • At least one test class extending com.splwg.base.api.testers.BatchJobTestCase. This class will perform automated tests on the batch process. The runs are performed within the test thread and transaction and all changes are rolled back at the end of the test.

After creating the background process, a corresponding entry should be made in the Batch Control table referencing the created BatchJob's class.

An example batch Job is com.splwg.base.domain.todo.batch.BatchErrorToDoCreation and the test is BatchErrorToDoCreationTest.