Discussion

How to use synchronize block in activity

Hi all,
In order to allow one thread to access block of code in java we place them in syncronize block.Like same way how to achevie this in PEGA?
we have couple of steps in an activity,only one thread to process the code at a time.
And Connect-wait function is not usefull for my scenario.

Please suggest how to achevie it.

Regards,
Aravind

**Moderation Team has archived post**

This post has been archived for educational purposes. Contents and links will no longer be updated. If you have the same/similar question, please write a new post.

Comments

Keep up to date on this post and subscribe to comments

May 16, 2012 - 4:20am

Not sure if there is an OOTB way in pega. But what you do in java should also work here(with some exceptions). Did you try using a synchronized block in an activity's java step, as you do in java code? Kind of :

[code]synchronized(this){

...
...
...

}[/code]

Exceptions:
1. The users that you want to provide synchronized access should have the same ruleset stack(coz, for each ruleset stack, the rule cache would differ). So if a user with a different ruleset stack also has access to this activity, he would be accessing this peice of synchronized code from another assembled rule(assembled java class for this activity with a different ruleset stack) for the same activity.

--Narayana.

May 16, 2012 - 2:03pm

The synchronized(this) block should work.

Though I'd disagree with Narayana on his exception. While there would be a different cache entry per ruleset stack, each would point to the same assembled java class for that activity.

Jon

June 25, 2014 - 4:49am

I tried using the below code

synchronized(this){
      for(int i=0;i<10;i++){
        oLog.infoForced("Value of i: "+i);
        try {
             Thread.sleep(1000);
        } catch (InterruptedException e) {
             oLog.error(e.getMessage());
        }
       }
    }

 

I logged in to the application using different operator ids, and ran the activity simultaneously. If synchronisation would have worked values of 'i' would be printed from 0 to 9 serially but instead of this those are jumbled up in the log file. Below is the output, 

 sandeep.ghosh- Starting activity.. 
 sandeep.ghosh- Value of i: 0 
 sandeep.ghosh- Value of i: 1 
 Abhishek.Sinha - Starting activity.. 
 Abhishek.Sinha - Value of i: 0 
 sandeep.ghosh- Value of i: 2 
 Abhishek.Sinha - Value of i: 1 
 sandeep.ghosh- Value of i: 3 
 Abhishek.Sinha - Value of i: 2 
 sandeep.ghosh- Value of i: 4 
 Abhishek.Sinha - Value of i: 3 
 sandeep.ghosh- Value of i: 5 
 Abhishek.Sinha - Value of i: 4 
 sandeep.ghosh- Value of i: 6 
 Abhishek.Sinha - Value of i: 5 
 sandeep.ghosh- Value of i: 7 
 Abhishek.Sinha - Value of i: 6 
 sandeep.ghosh- Value of i: 8 
 Abhishek.Sinha - Value of i: 7 
 sandeep.ghosh- Value of i: 9 
 Abhishek.Sinha - Value of i: 8 
 Abhishek.Sinha - Value of i: 9 

So synchronized(this) is not working

July 7, 2014 - 11:11am

The code written in java steps will be put inside the generated java class for the activity as inline code. 

Is both the operators point to same access group?

What version of PRPC and JVM you are using?

 

Interesting problem to raise as an SR.