cancel
Showing results for 
Search instead for 
Did you mean: 

JavaDelegate - local Variables

rangoo
Champ in-the-making
Champ in-the-making
I am using Java Serice Task to get and set some processing variables. something like this.


public class CustomDelegate implements JavaDelegate {
 
  public void execute(DelegateExecution execution) throws Exception {

//Counter
         int    i= (Integer)execution.getVariable("count");
        if(i<5) { i= i+ 1;
             execution.setVariable("count", i);
       }

//External call
   String orderID= (String) execution.getVariable("orderID");
        String status= MyUtil.getStatus(orderID);
         execution.setVariable("status", status);

}}


We have multiple orders and so mutliple threads. As recommended in userguide - we are not using any member variables. But using  local variables. But the last sentence in user guide says [red] class must be thread-safe[/red] too.

Do we still need to make our custom javadelegate  thread safe(using synchronize) ? Is it because references to variables are mutable?

2 REPLIES 2

frederikherema1
Star Contributor
Star Contributor
As long as all stuff you do in the execute() method doesn't use any fields of the CustomDelegate class, other than "Expression", you're safe…

rangoo
Champ in-the-making
Champ in-the-making
Great. Thank You!