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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

Implemented Multithreading using run base batch , but batch run time is not decreasing !! help

(1) ShareShare
ReportReport
Posted on by 6

I have implemented multithreading using run base batch framework but when I run it, it gets multiple tasks, but batch run time did not decreased (tested same logic without multithreading in both cases time is same) I am adding my code, please help with what I have done wrong , added code in reply section

time takeen , 2 minutes for my business logic without multithreading

after implementing multithreading and below code time was same, it should reduce because I have added 10 run time tasks.

I have the same question (0)
  • Sachin Mittal Profile Picture
    6 on at
    class MultiThreadRunBaseTask extends RunBaseBatch 
    //using this class to add runtime tasks , and on action menu item
    {
        BatchHeader batchHeader;
            SalesTable                          j;

        public static void main(Args args)
        {
            MultiThreadRunBaseTask  objMultiThread = new MultiThreadRunBaseTask();
            if (objMultiThread.prompt())
            {
                objMultiThread.run();
            }
        }
        void run()
        {
            MultiThreadRunBaseBatch             multiThreadRunBaseBatch;
            try
            {
                while select firstonly10 j
                {
                    if(this.isInBatch())
                    {
                        if(!batchHeader)
                        {
                            batchHeader = BatchHeader::construct(this.parmCurrentBatch().BatchJobId);
                        }
                        batchHeader.parmCaption("Multiple thread batch jobs");
                        MultiThreadRunBaseBatch =  new MultiThreadRunBaseBatch();
                        MultiThreadRunBaseBatch.pramSalesBuffer(j.data());
                        batchHeader.addRuntimeTask(MultiThreadRunBaseBatch, this.parmCurrentBatch().RecId);
                    }
                    else
                    {
                        // execute your code here when not running in batch
                    }
                }
                if(batchHeader)
                {
                    batchHeader.save();
                }
            }
            catch
            {
                info(strFmt("%1",xSession::xppCallStack()));
            }
        }
        public container pack()
        {
            return conNull();
        }
        public boolean unpack(container packedClass)
        {
            return true;
        }
    }
  • Sachin Mittal Profile Picture
    6 on at
    class MultiThreadRunBaseBatch extends RunBaseBatch
    {
        #define.CurrentVersion(1)
        #localmacro.CurrentList
            salesTableBuffer
        #endmacro
     
        SalesTable          salesTableBuffer;

        public boolean canGoBatchJournal()
        {
            return true;
        }

        protected boolean canRunInNewSession()
        {
            return true;
        }

        public boolean runsImpersonated()
        {
            return true;
        }
     
        public container pack()
        {
            return [#CurrentVersion, #CurrentList];
        }

        public boolean unpack(container packedClass)
        {
            Version version = runbase::getVersion(packedClass);
            switch (version)
            {
                case #CurrentVersion:
                    [version, #CurrentList] = packedClass;
                    break;
                default:
                    return false;
            }
            return true;
        }

        static ClassDescription description()
        {
            return 'MultiThreading RunBaseBatch FrameWork';
        }

        server static MultiThreadRunBaseBatch construct()
        {
            return new MultiThreadRunBaseBatch();
        }

        static void main(Args args)
        {
            MultiThreadRunBaseBatch   multiThread;
            multiThread = MultiThreadRunBaseBatch::construct();
            if (multiThread.prompt())
            {
                multiThread.run();
            }
        }
       
        public void pramSalesBuffer(SalesTable _sales)
        {
            salesTableBuffer=_sales;
        }

        public void run()
        {
            try
            {
                DemoBusinessLogic demoBusinessLogic = new DemoBusinessLogic();
                demoBusinessLogic.UpdateData(salesTableBuffer);
            }
            catch
            {
                info(strFmt("%1",xSession::xppCallStack()));
            }
        }
    }
  • André Arnaud de Calavon Profile Picture
    305,465 Super User 2026 Season 1 on at
    Hi Sachin,
     
    Can you tell what exactly the batch job should do? When using multiple threads, depending on the circumstances, it won't be faster. If you have a few records to process, a single thread could be faster. In case there are locks on several tables, the multi-thread might make things worse. 
     
    Using a single or multiple threads should be part of the design with a careful decision. I would suggest using the Trace parser tool to find out what exact coding or database calls are causing a delay. Then you can find out what to improve. We don't know what exactly is being executed in your DemoBusinessLogic class.
  • Sachin Mittal Profile Picture
    6 on at
    for demonstration purposes (to implement multithreading), in demobusinesslogic class, I have added 25 fields in sales table of type string, assigned some values to all these fields. 
    so running batch job will fill values in all 25 fields.
  • Martin Dráb Profile Picture
    239,660 Most Valuable Professional on at
    This seems to be a duplicate of your other thread, How implement multi-threading using SysOperation framework. There you also talked about 25 fields, which is useless information, and told us nothing about what actions you run in parallel.
     
    Starting the same discussion again from scratch is a waste of time. Instead, you need to give us better information.

    If you use multithreading in a wrong way, you may indeed get no benefit or even worse performance (because of an overhead).
  • Balbir Singh Profile Picture
    5 on at
    Assuming that threads are created correctly. One factor that can affect the performance of your batch job is the number of threads . Sometimes, your batch job tasks may have to wait for other batch jobs that are running at the same time, which can make it take longer to finish. To test this, you can try disabling other batch jobs and see if your batch job runs faster. When you configure your batch job in the Production environment, you can also use the Priority based scheduling option to reduce the waiting time for your batch job tasks.
     
     
     
     
  • Sachin Mittal Profile Picture
    6 on at
    yes, I understand that, but I have implemented my same logic using sysoperation framework, that is working absolutely fine (multiple tasks gets created, also batch time reduced to 12 sec from 3 minutes , adding Sc too ) I don't understand why run base is not working

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

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

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 671

#2
André Arnaud de Calavon Profile Picture

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

#3
Abhilash Warrier Profile Picture

Abhilash Warrier 589 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans