
Hi Team,
I have created multi threaded batch job to process the imported records from custom table, as per my logic I am creating threads according to the Journal numbers.
But the issue is I am not able to execute all the thread at once, system is executing some threads first and then waiting for to start next thread unless previous all should get ended.
Below is the code -
void run()
{
MTDEVTutorialBatchMultipleThreadBaseAllInsert multiThreadTask;
MTCentralDataHubTable centralDataHubTable;
while select LedgerJournalId from centralDataHubTable
group by LedgerJournalId
where centralDataHubTable.OperationType == str2int(operationType)
&& centralDataHubTable.Processed == NoYes::No
{
try
{
if(this.isInBatch())
{
if(!batchHeader)
{
batchHeader = BatchHeader::construct(this.parmCurrentBatch().BatchJobId);
}
batchHeader.parmCaption("Import vendor invoice journal");
multiThreadTask = new MTDEVTutorialBatchMultipleThreadBaseAllInsert();
multiThreadTask.parmCentralDataHubTable(centralDataHubTable.data());
batchHeader.addRuntimeTask(multiThreadTask, this.parmCurrentBatch().RecId);
}
else
{
throw Error("Execution must be scheduled in batch.");
}
}
catch (Exception::DuplicateKeyException)
{
retry;
}
catch(Exception::DuplicateKeyExceptionNotRecovered)
{
warning("Not recovered");
}
catch
{
info(strFmt("%1",xSession::xppCallStack()));
}
}
if(batchHeader)
{
// save the batchheader with added tasks
batchHeader.save();
}
}Batch Job screen:
I am expecting like all thread should start at once.
Please suggest me the best approach to write this logic and how can i increase the performance.
Please check the link below, you may need to check AOS instances.
A batch task is an activity that is run by a batch job. You can add batch tasks that have multiple types of dependencies to a batch job. You can also configure AOS instances to run multiple threads, each of which runs a task. All batch tasks that are waiting to be run can be run by any available AOS instance that is configured as a batch server. To improve throughput and reduce overall execution time, you can define a batch job as many tasks and then use a batch server to run the tasks against all available AOS instances.