Tuesday, May 18, 2010

Running concurrent processes in PeopleSoft

Problem Statement:
Running processes concurrently in PeopleSoft on run time .

Requirement:
Process simulated set of data from online pages.

Solution:
Concurrency can be achieved by synchronization. 

Details:

I have requirement to simulate data based on run control parameters and display on the same page. Users can select all data to process or can select some data to process and this can be done by multiple users at a time. 

In Campus Solutions, Maintain Application is a big component and can't be processed online with many students as this degrade the performance of system and might result in time out. I have to update the Maintain Application component for the simulated students selected by users. 

In order to achieve above, I have created a queue which will store all the request to run the process. This queue is Oracle physical table which will store lock flag with Process ID. Process ID is generated by a sequence on each request to process data and will be stored with Lock flag as U - unlocked in the table.

Process will be written in such a way that it will always check for L-lock records in the queue created above. If exists then it lets the process to sleep for some time otherwise proceed with the processing after applying Lock to the queue.

Other processes will wait till the time Lock is released by the process running. Once the process acquiring lock completes then it will release the lock by updating status to U-Unlock. Once, a process is awake and it finds the queue unlocked then it acquires the lock and executes the process.

Queue Record:
Process ID
Lock Flag
Other Fields

Translate for Lock Flag:
L-Locked
U-Unlocked

Sample code:

/*Locking mechanism - When there is no locked row in S3_RANK_RC then while loop will go inside else and lock record for current Runcontrol.
This will act as a lock for the other processes to process. Lock will only be released once the processing is completed for current RUNCNTLID in 
closing section where deletion happens.
LOCK_FLAG values
L - Locked U - Unlocked*/
While True
   SQLExec("select count(LOCK_FLAG) from PS_S3_RANK_RC where LOCK_FLAG='L'  ", &runStat);
   If (&runStat > 0) Then
      MessageBox(0, "", 30201, 12, "Process already running. Please run after some time.");
      GetJavaClass("java.lang.Thread").sleep(2 * 60 * 1000);
   Else
      SQLExec("BEGIN Update PS_S3_RANK_RC set LOCK_FLAG='L' where RUNCNTLID=:1; Commit; END;", S3_S3AD0022_AET.RUN_CNTL_ID.Value);
      Break;
   End-If;

End-While;

Regards
Karmveer