web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Multithreaded batch job is waiting to finish previous all started thread.

(0) ShareShare
ReportReport
Posted on by 487

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:
8836.pastedimage1655193508503v1.png

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.

I have the same question (0)
  • Suggested answer
    BillurSamdancioglu Profile Picture
    20,521 Most Valuable Professional on at

    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.

    docs.microsoft.com/.../batch-server-overview

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 510 Super User 2026 Season 1

#2
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 399

#3
Adis Profile Picture

Adis 251 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans