Speed up your execution performance by using SysGlobalCaches
Ever come across a situation where you needed to
a. Using a multi-threaded batch to import a journal header and lines, from a staging table. The table already contains the Journal Ids which you need to assign to the header and allocate the lines under that header.
b. You need to continuously check after each line being imported, if the journal with the Id has been created. If not, it will create the header and create the lines under it; If yes, it will directly create the lines for the header (Find or create).
c. As you could rightly guess, this architecture has an inherent sluggishness associated with it -- each time you keep on checking if the header has been created or not, it does mean a lot of performance effects, as a consequence. Also as you can understand it's a multithreaded code, which means each thread has no direct relation with the other -- which does mean there is no way I can talk between the threads/pass on any information.
SysGlobalCaches to the rescue:
I personally prefer to use SysGlobalCaches for all such situations. Imagine using a Map and you are stacking up the journal number and generated Journal header record in it.
Map journalMapInfo = new Map(Types::string, Types::Record);
Please note, that you need to do this at the child task class of the batch [for example the child batch class which in turn takes up each task to process things further (e.g.: finding and creating journal header and lines)].
SysGlobalCache journalGlobalCache globalCache = appl.globalCache();
Check if journalMapInfo value is already in the globalcache object:
if (appl.globalCache().isSet(owner, key) == true)
{
journalMapInfo =
appl.globalCache().get(owner, key);
ledgerJournalTable = journalMapInfo.Lookup(JournalMapInfo, journalId);
}
if not, then here you are assigning the journal Id and record generated:
journalMapInfo.insert(journalNum, ledgerJournalTable);
And then you store the map in the globalcache:
Can you please give us a code snippest? (the small and working code snippest which we can refere and understand the actual implementation of sysGlobalCache)
ReplyDelete