PRG10.Multi Threading in T24-R13
PRG10.Multi Threading in T24-R13
PRG10.Multi Threading in T24-R13
2 So has this changed the way we write all routines in T24? Actually no. Version and
Enquiry routines are still single threaded.
3 Multi threading has been extensively used in COB routines and Services (multi
threaded phantoms or background processes)
4 Multi threading obviously has its advantages over single threaded routines and allow
you to make maximum use of the server’s processor capabilities.
2 The task given to you is to select all account records and print the currency and
working balances for each. Take a piece of paper and try to write down an algorithm
for this task.
2 Open the ACCOUNT application because that’s the file to read from
3 Form the SELECT statement and execute it to arrive at a list of all ACCOUNT ids.
4 For each Id in the list, the record is read and the required field details are extracted
and displayed.
Now if you were to execute this subroutine, one processes is started at operating
system level for this and this processes is solely responsible for processing the entire
list of Id’s. Now what if you could have multiple processes to process the same set of
Ids. Would this reduce the overall time for execution?
Executing multiple copies of the single threaded routine that you just wrote – will that
solve the problem? No it will not - since each copy of the routine will be selecting from
the ACCOUNT application and each will routine will process the same list of Ids.
Thus the SELECT must happen independent of the routines processing the ids. So
how you access these id’s? If they are stored in memory, it is not possible to access
them. The only way is write them to a file and allow access to it.
1 The SELECT routine must be executed first otherwise the record processing
subroutine has nothing to work with.
2 The list of ids selected must be written into a common file so that the processing
subroutine (and multiple copies of it) know where to pick up ids from.
3 4 Multiple copies of the processing routine can now be started and the work load is
distributed.
2 So, you now have to write a subroutine to LOAD or initialise these common
variables.
3 Since these common variables are specific to your routine, you must define them as
well.
You will now learn how to multi thread the subroutine you saw earlier.
The next component that must be created is called the .LOAD subroutine. If you
decide the name of your multi threaded subroutine is ACCOUNT.LIST, then this
subroutine must be called ACCOUNT.LIST.LOAD. In this subroutine, you must
initialise all the common variables defined in the common file. Remember to include
this common file in the .LOAD routine.
A good practice to follow when creating I_ files to hold common variables is to define
each variable on a new line and use the ;* to add a comment that describes the use of
each variable. For example, if you redid the I_ACCOUNT.LIST.COMMON it would
look like this
*Content of I_ACCOUNT.LIST.COMMON
COM /ACCOUNT.LIST/ FN.ACCOUNT, ;* File Name of the ACCOUNT file to be
opened
F.ACCOUNT, ;* File Path return from OPF for the ACCOUNT file
Note: The file from which id’s have to be selected along with selection criteria can be
specified in the dynamic array passed as first parameter to BATCH.BUILD.LIST. This
eliminates the need for using EB.READLIST to perform the select.
The last component is the RECORD or PROCESS routine. It takes one parameter.
You guessed right, it is the ID from the list to be processed. The looping structure has
been left out of the subroutine logic totally.
Now that you have learnt the components of a multi threaded routine, let’s take a look
at how to execute it.
2. No, there is only one PGM.FILE entry per multi threaded routine. The ID of the
PGM.FILE must be the name of the process or record routine. In the example that you
are looking at – ACCOUNT.LIST
3. This multi-threaded routine can either be run as a Service or as a COB Job. This
learning unit does not include details on how to execute a service or COB. You will
learn this in the session on COB and its execution
5. So, then how do we say that a routine is running in a multithreaded fashion. How is
it improving performance? This is done by starting multiple tSA’s. The next slide will
help you visualise this better.
2. Lets assume the name of the first variable is PARAM. The variable name can be any generic name.
2.1 The first position in the array denotes the name of the list file to be created with the selected ids. This is always
null, T24 decides the name of the LIST FILE. Normally the name of the LIST FILE will be F.JOB.LIST.<Seq No> for
eg: F.JOB.LIST.1
2.2 The second position can be used to pass an application (F.APPLICATION name) so that BATCH.BUILD.LIST
itself can form and execute the SELECT for you.
2.3 The criteria for the selection can be passed in the third position if any.
2.4 The fourth position contains the last ID in the LIST FILE. So if the last record ID in the LIST FILE is 101, meaning
there are 101 records, this position will contain the value 101.
2.5 The fifth position contains the total number of contacts selected and written on to the list file. Let’s assume you
did a select on the FUNDS.TRANSFER application, and 110 contracts were selected and written, then 110 will be
returned by BATCH.BUILD.LIST to this position.
2.6 When T24 processes each ID from the list it is wrapped around a transaction boundary. Using the sixth position
you can decide at you own risk and bulk transactions. In other words, multiple ids can be processed in one
transaction boundary. The number of ids to bulk is mentioned here.
The routine has one parameter that must be set to NULL in order to discard the
current id from the list.
You must remember never to perform any IO from within the .FILTER routine as it will
be a performance bottleneck.
The routine must follow the naming convention used in the .LOAD and .SELECT
You can also see the common variable BATCH.LIST.FILE has been hardcoded in this
routine. This should not be done as T24 will decide the name of the LIST FILE. In this
example I have used it for illustration purposes.
To execute this program, login to T24 once and log out, so that the common variables
are set.
Show below is the screen shot of the contents of the LIST FILE.
2. Multi threaded routines (jobs) though effective in distributing the load on multiple agents has a
drawback in terms of sequencing the job. For example, an accrual processing job in LD over a
weekend shall accrue for all the contracts on Friday, then again on Saturday and again on Sunday.
Here agents shall together process the accrual for Friday and on completion of this start the processing
for Saturday. After completing the same, it should go over to Sunday.
Here we cannot do the following:
a.) Select all contracts and accrue for Friday/Saturday/Sunday in one go, as we want to finish Friday’s
work and then go to Saturday
b.) Run three different jobs, as the list will become infinite
Thus, there is a requirement for jobs to determine sequences and multi thread within every
sequence. Both sequence and performance has to be kept in mind.
3. This can be filled in the .SELECT routine (only the first time) when it is invoked. And then .SELECT will
be invoked for every value in CONTROL.LIST. The first invocation where we fill in the values is the
invocation for the first value in CONTROL.LIST.
4. Since .SELECT is called multiple times, the job can perform the select accordingly (First time for
Friday, second time for Saturday etc…) and the LIST FILE will be populated. The processing then will
happen based on what is there in LIST FILE and once finished we will invoke .SELECT for the next
value in CONTROL.LIST
5. As you have already learnt, BATCH.JOB.CONTROL is the core routine that is responsible for executing
a Multi-threaded routine. Within this logic, there is a file called F.BATCH.STATUS, that contains the
Always the first value in CONTROL.LIST will be the current value to be processed, as
you just learnt that once values are processed in CONTROL.LIST its removed from
the variable.
CONTROL.LIST variable is populated with dummy values AC and CUST, one for
account and the other for customer.