In order to achieve synchronization and to ensure that only one process instance is able to run a set of activities grouped together at a particular time; Critical Section Group type is used in TIBCO processes. In this step by step tutorial, I will explain and demonstrate how we can use Critical Section groups to make sure that certain action can be taken only by one process instance at a time.
Example Business Scenario:
A TIBCO BW process updates account balance of account holders by deducting 10 out of the available balance every time It runs. In order to make sure that there is no mismatch or anomaly in the balance of the account holder; we want to make sure that only one process instance at a time can run through the JDBC Update activity in the process.
We are going to achieve the above stated goal by using Critical Section group. Please note that this is just a raw example in order to demonstrate critical section usage and may not necessarily fit in a real time practical scenario.
Let’s now proceed step by step with TIBCO BW Critical Section group tutorial.
Step 1: Configure JDBC Connection and Prepare sample data in database table
In this preliminary step; we are going to first add JDBC Connection resource in our project and configure it so that we are able to connect to the database. I am using Oracle database for this tutorial.
From JDBC Palette, drag JDBC Connection resource in the project and configure it as per your database settings (by specifying username, password, Schema name etc). JDBC Connection configuration in my case is shown in below screenshot:
Using Test Connection button, make sure that you are able to connect to the database.
In the database, create a table TBL_ACCOUNT and populate it with some sample data as shown below:
Step 2: Create Process with Critical Section Group
Create a new process and add JDBC Update activity in the process. In the configuration of this JDBC Update activity, write below sql statement which will update balance of account holder ‘ajmal’ by deducting 10.
Configuration of JDBC Update is shown in below screenshot:
Just in order to simulate how process instances will wait for previous instance to complete, add a Sleep activity just after JDBC Update activity and give it 60000 as an input so that It sleeps the process instance for 1 minute:
Now using Create a group option from the menu bar, enclose JDBC Update and Sleep activities in a group. In the configuration of the group; choose Critical Section as Group Action and Single Group as Scope. (Multiple Group example will be explained in another tutorial).
Group configuration is shown in below screenshot:
Now our process is ready with all necessary configurations for different activities involved. Complete process will look like below:
Step 3: Test Critical Section Group Process in designer tester
Load the process in designer tester so that its instance starts running.
While this instance is running inside critical section and is in Sleep state; create another job (another instance) of the process. As you can see in below screenshot; second instance isn’t executing the critical section as It’s waiting for the first instance to complete its critical section execution.
Once the execution of 1st instance is completed; second instance will also run through the critical section.
This completes Single group critical section tutorial. Hope it will help you to understand the concept. Feel free to comment/contact for any further help. Thanks