1

I'm creating task using TaskService using below snippet.

    Task task = taskService.newTask();
    task.setName(taskName);
    task.setParentTaskId(taskParentId);
    task.setDescription(taskDescription);
    task.setCategory(taskCategory);
    taskService.saveTask(task);

I have got a requirement where I need to create multiple tasks(1000) but taskService.saveTask() is taking too much time to create these many tasks. Tried exploring the Activiti APIs but couldn't find any API related to bulk task creation. Does Activiti support bulk task creation? If not, can someone share an alternate to handle this scenario?

Pratik Ambani
  • 2,523
  • 1
  • 18
  • 28
  • 1
    What is the "scenario". Meaning what is the business scenario that needs 1000 tasks created simultaneously? – Greg Harley Dec 23 '21 at 15:06
  • @GregHarley There is a business usecase where upon certain conditions X individual tasks should get generated – Pratik Ambani Jan 02 '22 at 06:21
  • Hi Pratik, My question really is. You say they service is taking too long to create these tasks. How long is too long and why do the tasks have to be created exactly at the same time? In a scenario like this the problem is more usually a poorly modeled process. Often you need to think about the problem differently. Also often you can use parallel execution (although Activiti parallel execution is still serialized - you should look at Flowable as it no includes true parallel execution). – Greg Harley Jan 10 '22 at 17:47

1 Answers1

1

You could use multiple Threads to create the tasks.

ExecutorService pool = Executors.newFixedThreadPool(1000);
for(int i=0;i<1000;i++)
{
    pool.execute(()->
    {
        Task task = taskService.newTask();
        task.setName(taskName);
        task.setParentTaskId(taskParentId);
        task.setDescription(taskDescription);
        task.setCategory(taskCategory);
        taskService.saveTask(task);
    });
}
Sascha
  • 1,320
  • 10
  • 16
  • Hi Sascha, not sure this would resolve the issue as I expect the "slowness" is coming from persistence into the database which will likely not improve. Nice suggestion though. – Greg Harley Jan 10 '22 at 17:32