Execution history examples

The batch and task classes are the same than into the previous tutorial.

MemoryExecutionHistory implementation

This implementation store the ids into the memory.

  • Configuration
    # MyBatchFramework configuration file (v. 1.0)
    
    mbf.batch.className = fr.cyberteche.batchservice.test.BatchTest
    
    mbf.threadPool.minSize = 1
    mbf.threadPool.maxSize = 2
    mbf.threadPool.blockingQueueCapacity = 2
    
    mbf.executionHistory.className = net.sf.mybatchfwk.history.MemoryExecutionHistory
    
  • Execution logs

    We can see that the list of completed and failed tasks are well displayed.

    18:56:32,093 INFO  [BatchTest.init] ###> init
    18:56:32,125 INFO  [BatchTest.execute] ###> begin execute
    18:56:32,125 INFO  [MyTask.run] [Task '1'] begin of execution
    18:56:32,125 INFO  [MyTask.run] [Task '2'] begin of execution
    18:56:34,125 INFO  [MyTask.run] [Task '1'] execution done
    18:56:34,125 INFO  [BatchTest.endOfExecution] task execution success: id='1'
    18:56:34,125 INFO  [BatchTest.execute] ###> end execute
    18:56:34,125 INFO  [MyTask.run] [Task '3'] begin of execution
    18:56:34,125 ERROR [BatchTest.endOfExecution] task execution failure: id='3'
    net.sf.mybatchfwk.TaskExecutionException: error of execution
            at net.sf.mybatchfwk.test.MyTask.run(MyTask.java:30)
            at net.sf.mybatchfwk.PausableThreadPoolExecutor$Worker.runTask(PausableThreadPoolExecutor.java:400)
            at net.sf.mybatchfwk.PausableThreadPoolExecutor$Worker.run(PausableThreadPoolExecutor.java:421)
            at java.lang.Thread.run(Unknown Source)
    18:56:34,140 INFO  [MyTask.run] [Task '4'] begin of execution
    18:56:34,140 INFO  [MyTask.run] [Task '2'] execution done
    18:56:34,140 INFO  [BatchTest.endOfExecution] task execution success: id='2'
    18:56:34,140 INFO  [MyTask.run] [Task '5'] begin of execution
    18:56:36,140 INFO  [MyTask.run] [Task '4'] execution done
    18:56:36,140 INFO  [BatchTest.endOfExecution] task execution success: id='4'
    18:56:36,140 INFO  [MyTask.run] [Task '5'] execution done
    18:56:36,140 INFO  [BatchTest.endOfExecution] task execution success: id='5'
    18:56:36,140 INFO  [BatchTest.end] ###> end
    18:56:36,140 INFO  [BatchTest.end] ###> ---Execution report---
    18:56:36,156 INFO  [BatchTest.end] Begin date: Sun Oct 22 18:56:32 CEST 2006
    18:56:36,156 INFO  [BatchTest.end] End date: Sun Oct 22 18:56:36 CEST 2006
    18:56:36,156 INFO  [BatchTest.end] Number of completed tasks: 4
    18:56:36,156 INFO  [BatchTest.end] Completed tasks: 1, 2, 4, 5
    18:56:36,156 INFO  [BatchTest.end] Number of failed tasks: 1
    18:56:36,171 INFO  [BatchTest.end] Failed tasks: 3
    18:56:36,171 INFO  [BatchTest.end] ###> ----------------------
    

FileExecutionHistory implementation

This implementation store the ids into files.

  • Configuration
    # MyBatchFramework configuration file (v. 1.0)
    
    mbf.batch.className = fr.cyberteche.batchservice.test.BatchTest
    
    mbf.threadPool.minSize = 1
    mbf.threadPool.maxSize = 2
    mbf.threadPool.blockingQueueCapacity = 2
    
    mbf.executionHistory.className = net.sf.mybatchfwk.history.FileExecutionHistory
    mbf.executionHistory.storageFolder = c:\\test
    
  • Execution logs

    We can see that the list of completed and failed tasks are well displayed.

    19:00:38,734 INFO  [BatchTest.init] ###> init
    19:00:38,765 INFO  [BatchTest.execute] ###> begin execute
    19:00:38,765 INFO  [MyTask.run] [Task '1'] begin of execution
    19:00:38,765 INFO  [MyTask.run] [Task '2'] begin of execution
    19:00:40,765 INFO  [MyTask.run] [Task '1'] execution done
    19:00:40,765 INFO  [BatchTest.endOfExecution] task execution success: id='1'
    19:00:40,765 INFO  [MyTask.run] [Task '3'] begin of execution
    19:00:40,781 ERROR [BatchTest.endOfExecution] task execution failure: id='3'
    net.sf.mybatchfwk.TaskExecutionException: error of execution
            at net.sf.mybatchfwk.test.MyTask.run(MyTask.java:30)
            at net.sf.mybatchfwk.PausableThreadPoolExecutor$Worker.runTask(PausableThreadPoolExecutor.java:400)
            at net.sf.mybatchfwk.PausableThreadPoolExecutor$Worker.run(PausableThreadPoolExecutor.java:421)
            at java.lang.Thread.run(Unknown Source)
    19:00:40,781 INFO  [MyTask.run] [Task '4'] begin of execution
    19:00:40,781 INFO  [MyTask.run] [Task '2'] execution done
    19:00:40,781 INFO  [BatchTest.endOfExecution] task execution success: id='2'
    19:00:40,781 INFO  [MyTask.run] [Task '5'] begin of execution
    19:00:40,781 INFO  [BatchTest.execute] ###> end execute
    19:00:42,781 INFO  [MyTask.run] [Task '4'] execution done
    19:00:42,781 INFO  [BatchTest.endOfExecution] task execution success: id='4'
    19:00:42,781 INFO  [MyTask.run] [Task '5'] execution done
    19:00:42,781 INFO  [BatchTest.endOfExecution] task execution success: id='5'
    19:00:42,781 INFO  [BatchTest.end] ###> end
    19:00:42,796 INFO  [BatchTest.end] ###> ---Execution report---
    19:00:42,812 INFO  [BatchTest.end] Begin date: Sun Oct 22 19:00:38 CEST 2006
    19:00:42,812 INFO  [BatchTest.end] End date: Sun Oct 22 19:00:42 CEST 2006
    19:00:42,812 INFO  [BatchTest.end] Number of completed tasks: 4
    19:00:42,812 INFO  [BatchTest.end] Completed tasks: 1, 2, 4, 5
    19:00:42,812 INFO  [BatchTest.end] Number of failed tasks: 1
    19:00:42,812 INFO  [BatchTest.end] Failed tasks: 3
    19:00:42,812 INFO  [BatchTest.end] ###> ----------------------
    

    Contents of the file c:\test\mbf-completedTasks.txt:

    1
    2
    4
    5
    

    Contents of the file c:\test\mbf-failedTasks.txt:

    3
    

    Imagine now that the user want to execute again the batch in order to execute the previously failed tasks, but without modify the java source. He just need to add two parameters, in order to specify that he doesn't want to execute the new and completed tasks:

    # MyBatchFramework configuration file (v. 1.0)
    
    mbf.batch.className = fr.cyberteche.batchservice.test.BatchTest
    mbf.batch.executeNewTasks = false
    mbf.batch.executeCompletedTasks = false
    
    mbf.threadPool.minSize = 1
    mbf.threadPool.maxSize = 2
    mbf.threadPool.blockingQueueCapacity = 2
    
    mbf.executionHistory.className = net.sf.mybatchfwk.history.FileExecutionHistory
    mbf.executionHistory.storageFolder = c:\\test
    

    Execution logs:

    19:36:55,718 INFO  [BatchTest.init] ###> init
    19:36:55,750 INFO  [BatchTest.execute] ###> begin execute
    19:36:55,750 INFO  [BatchTest.execute] ###> end execute
    19:36:55,750 INFO  [MyTask.run] [Task '3'] begin of execution
    19:36:55,781 ERROR [BatchTest.endOfExecution] task execution failure: id='3'
    net.sf.mybatchfwk.TaskExecutionException: error of execution
            at net.sf.mybatchfwk.test.MyTask.run(MyTask.java:30)
            at net.sf.mybatchfwk.PausableThreadPoolExecutor$Worker.runTask(PausableThreadPoolExecutor.java:400)
            at net.sf.mybatchfwk.PausableThreadPoolExecutor$Worker.run(PausableThreadPoolExecutor.java:421)
            at java.lang.Thread.run(Unknown Source)
    19:36:55,781 INFO  [BatchTest.end] ###> end
    19:36:55,781 INFO  [BatchTest.end] ###> ---Execution report---
    19:36:55,796 INFO  [BatchTest.end] Begin date: Sun Oct 22 19:36:55 CEST 2006
    19:36:55,796 INFO  [BatchTest.end] End date: Sun Oct 22 19:36:55 CEST 2006
    19:36:55,796 INFO  [BatchTest.end] Number of completed tasks: 0
    19:36:55,812 INFO  [BatchTest.end] Completed tasks: 
    19:36:55,812 INFO  [BatchTest.end] Number of failed tasks: 1
    19:36:55,812 INFO  [BatchTest.end] Failed tasks: 3
    19:36:55,812 INFO  [BatchTest.end] ###> ----------------------
    

    With the three parameters executeNewTasks, executeCompletedTasks and executeFailedTasks, the user can filter the tasks before execution. Six possibilities of filtration: new+completed, new+failed, completed+failed, new, failed, completed.