Multithreading

  • Uploaded by: Alfredo Soto
  • 0
  • 0
  • January 2021
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Multithreading as PDF for free.

More details

  • Words: 1,572
  • Pages: 28
Loading documents preview...
1

Multithreading

Objectives

Objectives Learning Objectives

Slid e2

2



Introduction to Services and multithreading in T24



Components of a multi-threaded routine



Writing a multithreaded program



Executing a multithreaded program



More on multithreading

Service

Slid e3

3 

Services are background multithreaded processes.



Services can be executed as a



Part of COB. COB itself is a service



An independent standalone online service

Slid e4

Components of a Service

4

JOB

BATCH

SERVICE

• • •

Is a unit of work executing a business transaction No need of user intervention. For example Interest capitalization for accounts.

Is a set of Jobs that form a business transaction.

Is a trigger to Execute a Batch

Slid e5

JOB

5



A job involves processing a set of records.



For example - Interest calculation Get list of IDs to process Find the balance for each ID Calculate interest Write to file

Slid e6

How jobs are multithreaded in T24

6

1

Service Agents

List of contracts to process

1

Server

Service Manager

2

2

Server

3 4

3

Server

5 6

If one agent terminates then its transaction is rolled back and the other agents process the contract. Add more agents to increase throughput

Slid e7

Components of a Service

7

JOB.LOAD

Initialise common variables BATCH.JOB.CONTROL

JOB.SELECT

Prepare list of IDs

JOB

Processing Logic

SERVICE

Demo multithreading

Slid e8

8

Requirement Issue gift voucher to all Customers in Modelbank



Algorithm 

Step 1 : Open CUSTOMER



Step 2 : Open EB.GIFT.VOUCHER



Step 3 : Initialise gift voucher value to 500



Step 4 : Prepare the list of Customer IDs to whom the gift vouchers will be issued



Step 5 : Loop through the IDs



5.1 : Read CUSTOMER record using the ID and get the name



5.2 : Write customer id, name and gift voucher amount to EB.GIFT.VOUCHER



Note: You must write EB.GIFT.VOUCHER, EB.GIFT.VOUCHER.FIELDS and run EB.DEV.HELPER to create the files

Slide 9

.LOAD Method

9

<JOB>.LOAD When is the method executed ?

First method to be executed How is the method used ?

Will be executed by each agent

Name <JOB-NAME>.LOAD In our example , this routine is used to: 1. Initialise the voucher amount. 2. Open CUSTOMER

How?

When?

3. Open EB.GIFT.VOUCHER The variables used here have to be declared in a common insert.

What?

What is the method used for? This method is used for initialising the common variables

Common Variables

Slide 10

10

I_<JOB>.COMMON

• This file is used for declaring the common variables

Slid e 11

SELECT Method

11

When is the method executed ?

<JOB>.SELECT

This is the method will be executed after LOAD routine Will be executed by ONE agent only

How is the method used ? Name <JOB-NAME>.SELECT In our example , this routine is used to : 1. To select the list of IDs to process.

How?

When?

2. Call API ‘BATCH.BUILD.LIST’ to write the selected IDs into a JOB LIST file

What?

What is the method used for?

This method is used to select the list of contracts

.SELECT (BATCH.BUILD.LIST)

Slide 12

12 

.SELECT routine calls BATCH.BUILD.LIST to perform the selection of contracts.



It takes 2 parameters



First parameter is a dynamic array (7 values in total)



Second parameter holds the ID list. 



EX : CALL BATCH.BUILD.LIST('',ID.LIST)

The first parameter can take the following 7 values in the order specified:

.SELECT (BATCH.BUILD.LIST)

Slide 13

13 

.SELECT routine calls BATCH.BUILD.LIST to perform the selection of contracts.



It takes 2 parameters



First parameter is a dynamic array (7 values in total)



Second parameter holds the ID list. 



EX : CALL BATCH.BUILD.LIST('',ID.LIST)

The first parameter can take the following 7 values in the order specified:

Slid e 14

RECORD routine

14

<JOB>

When is the method executed ? This method will be executed after the list of IDs to be

How is the method used ?

processed is ready .

Name - <JOB-NAME>

This method will be executed once for each ID in the

In our example , this routine is used

list

to:

1. Read the CUSTOMER record using the ID received as parameter

How?

When?

2. Get Customer Name

3. Write the Customer ID, Name and Voucher amount to

What?

EB.GIFT.VOUCHER What is the method used for? This method implements the processing logic

Slid e 15

Solution *Contents of I_GIFT.VOUCHER.COMMON I_GIFT.VOUCHER.COMMON Common Variables COM/GIFT.VOUCHER/FN.CUSTOMER, F.CUSTOMER, F.GIFT.VOUCHER, SUBROUTINE GIFT.VOUCHER.LOAD FN.GIFT.VOUCHER, VOUCHER.VALUE I_COMMON *Customers will be issued a$INSERT gift voucher of GIFT.VOUCHER.LOAD $INSERT I_EQUATE value 500 $INSERT I_GIFT.VOUCHER.COMMON VOUCHER.VALUE = 500 FN. CUSTOMER='F.CUSTOMER' F. CUSTOMER='' SUBROUTINE GIFT.VOUCHER.SELECT CALL OPF(FN.CUSTOMER,F.CUSTOMER) GIFT.VOUCHER.SELECT $INSERT I_COMMON FN.GIFT.VOUCHER='F.EB.GIFT.VOUCHER' $INSERT I_EQUATE F.GIFT.VOUCHER='' SUBROUTINE GIFT.VOUCHER(ID) $INSERT I_GIFT.VOUCHER.COMMON CALL OPF(FN.EB.GIFT.VOUCHER,F.GIFT.VOUCHER) $INSERT I_COMMON SEL.LIST=‘’ RETURN $INSERT I_EQUATE BBL.DATA=‘’ END $INSERT I_F.CUSTOMER BBL.DATA<2>=‘F.CUSTOMER’ $INSERT I_GIFT.VOUCHER.COMMON CALL BATCH.BUILD.LIST(BBL.DATA,SEL.LIST) CALL F.READ(FN.CUSTOMER,ID,R.CUSTOMER,F.CUSTOMER,READ.ERR) RETURN CUSTOMER.NAME= R.CUSTOMER<EB.CUS.SHORT.NAME> END R.GIFT.VOUCHER='' R.GIFT.VOUCHER<-1>=ID R.GIFT.VOUCHER<-1>=CUSTOMER.NAME R.GIFT.VOUCHER<-1>=VOUCHER.VALUE CALL F.WRITE(FN.GIFT.VOUCHER,ID,R.GIFT.VOUCHER) RETURN END GIFT.VOUCHER

15

Configuring a job in T24 17

 Create a PGM.FILE entry with B as TYPE and BATCH.JOB as @BATCH.JOB.CONTROL.

 Create a BATCH record with the JOB.NAME as PGM.FILE record ID.

 Create a TSA.SERVICE record with the ID same as BATCH record ID.

 Start TSM.  Note down the TSA ID for your routine.  Now start the TSAs

Configuring a job in T24 18

Slid e 19

How does T24 process the JOB

19

Agent 1

Agent 2

Initialise CommonVariables

Initialise Common Variables BJC BJC

Create List File

Get the Contract to process

Get the Contract to process

ID 31

100724 120019

Data 1

100724

2

100112

Begin Transaction

Customer

Commit

100725 100112

Begin Transaction

Issue gift voucher 100724 120019

42

500

3

120019

4

100725

Gift Voucher

Issue Gift Voucher 100112 100725

Customer Customer

500 500

Commit

Continue till the end of list file

Workshop

Workshop Workshop

Slid e 20

20



Write a multi threaded routine to set the status of the debit card issued.



Use DAS routine to fetch the list of Debit Card IDs

What if you want to process selected records

Slid e 21

21 

You can implement this in 2 ways:



Filter criteria in SELECT routine



A .FILTER routine



When the selection is not based on a simple criteria, a .FILTER routine is written. For eg IF

FIELD(ID,"-",2) GT TODAY THEN



ID = "" ; * not due

END 

ELSE

ID = FIELD(ID,"-",1) ; * set to account number

END

Slide 22

FILTER Method

22

.FILTER

When is the method executed ? This routine is called from BATCH.BUILD.LIST for each Contract ID selected

How is the method used ? Name - <JOB-NAME>.FILTER

How?

When?

What?

What is the method used for? This is method called once per contract , to decide whether it must

be part of the list file or not

.FILTER routine – an example

Slid e 23

23

SUBROUTINE GIFT.VOUCHER.FILTER(ID) $INSERT I_COMMON $INSERT I_EQUATE $INSERT I_F.CUSTOMER $INSERT I_GIFT.VOUCHER.COMMON CUSTOMER.ID.PREFIX=SUBSTRINGS(ID,1,3) IF CUSTOMER.ID.PREFIX NE 100 THEN ID = “” END RETURN END

CONTROL.LIST 24

Interest is accrued on working days Interest must be accrued for weekend also.

Interest Accrual Current Date

Interest Accrual Current Date + 1

CONTROL.LIST

1. 2. 3.

A variable in I_BATCH.FILES Used for sequencing Initialised and controlled in .SELECT routine

Interest Accrual Current Date + 2

CONTROL.LIST 25

Interest is accrued on working days Interest must be accrued for weekend also.

Interest Accrual Current Date

Interest Accrual Current Date + 1

CONTROL.LIST

1. 2. 3.

A variable in I_BATCH.FILES Used for sequencing Initialised and controlled in .SELECT routine

Interest Accrual Current Date + 2

Sample .SELECT with CONTROL.LIST populated

Slid e 26

26

SUBROUTINE LD.INTERESTT.SELECT $INSERT I_COMMON $INSERT I_EQUATE $INSERT I_BATCH.FILES $INSERT I_F.DATES *First time it will be NULL so go build it IF NOT(CONTROL.LIST) THEN CURR.DATE=TODAY NEXT.DATE=R.DATES(EB.DATNEXT.WORKING.DAY) CALL CDT(‘’,NEXT.DATE,’-1C’) IF CURR.DATE NE NEXT.DATE THEN GOSUB BUILD.CONTROL.LIST END END FN.FILE.NAME = ‘F.LD.LOANS.AND.DEPOSITS’ *Second call to BBL to build CUSTOMER LIST GOSUB CALL.BBL RETURN

CALL.BBL: SEL.CMD = 'SELECT ':FN.FILE.NAME ID.LIST = ''; NO.RECS = ‘’ CALL EB.READLIST(SEL.CMD, ID.LIST,'',NO.RECS, '') IF ID.LIST THEN LIST.PARAMETERS = '' CALL BATCH.BUILD.LIST(LIST.PARAMETERS, ID.LIST) END RETURN BUILD.CONTROL.LIST: CONTROL.LIST = ‘CALCULATE.INTEREST’ CONTROL.LIST<-1> = ‘CALCULATE.INTEREST’ CONTROL.LIST<-1>=‘CALCULATE.INTEREST’ RETURN END

Slid e 27

How does T24 process the JOB Repeat the process till the end of the CONTROL.LIST

Agent 1 Initialise Global Variables

List 1

CONTROL.LIST

List 2

27

Agent 2 Initialise Global Variables

Create List File

BJC BJC

Get the Contract to process

Get the Contract to process

ID 3

120019

Data 1

100724

2

100112

4

Begin Transaction

Begin Transaction Issue gift voucher

120019

Customer

Commit

100725

500

3

120019

4

100725

Issue Gift Voucher

Gift Voucher

100725

100724

Customer

500

100112

Customer

500

Customer

Commit

500

Quiz

Quiz – True/False

Slid e 28

28

1.

Every multi threaded routine has three entries in PGM.FILE for the .LOAD, .SELECT and record routine

2.

Select routine is executed by all the tSAs

3.

BATCH.BUILD.LIST is the subroutine which writes the selected contract ids into the LIST FILE

4.

CONTROL.LIST is a common variable defined in I_COMMON

5.

Filter routine is executed once for each for each Contract ID

Objectives

Summary Learning Objectives

Slid e 29

29

In this learning unit you learnt about



The various parts of a Multi threaded subroutine in

T24 

The use of each part of the Multi threaded subroutine in T24



How to execute a multi threaded routine in T24

Related Documents

Multithreading
January 2021 3

More Documents from "Alfredo Soto"