Background – In Microsoft Dynamics D365 Finance and Operations, most of the processes & batch jobs run in a single thread and supports only single thread execution not multi-threading. Generally Single Thread batch Jobs or processes work well in Microsoft Dynamics 365 Fins and ops. But there are many scenarios where we require fast performance and quick competition of processes and batch jobs. Multithreading Batch Jobs approach is very useful in those scenarios.
Two Different Ways – In Microsoft Dynamics D365 Finance and Operations,We can develop Multithreaded Batch Jobs in two ways. The first approach is using PESSIMISTIC LOCKS OR PESSIMISTIC SELECT in Microsoft Dynamics D365 Finance and Operations.
The second is to create BATCH TASKs. Batch Task approach you can find in standard classes like RetailStatementCalculate_Multi, RetailStatementPost_Multi Etc. which are using RunBaseBatch Framework (Not SYSOperation Framework) inside Microsoft Dynamics D365 Finance and Operations.
Lets begin with first approach i.e. using PESSIMISTIC LOCKS OR PESSIMISTIC SELECT in Microsoft Dynamics D365 Finance and Operations.By default, D365 fins and ops supports Optimistic Concurrency model (OCC) during the time SELECT or fetching records from database of Microsoft Dynamics D365 Finance and Operations. Optimistic Concurrency Model or SELECT only locks records during the time of Update whereas Pessimistic Concurrency Control (PCC).
Below code you can utilize in batch jobs and you run multiple thread of same batch job class as we a
Lets move to second approach , which include create and adding RUNTIME task using BATCHHEADER class . Here a single Runbase Batch Job is used for creating multiple threads or Runtime Tasks.