cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Multithreading during model save

neha_gupta03
Associate
Associate
0 Kudos
1,797

Hi,

If a model is being updated by two different threads with different attributes. For ex one thread is called from OCC service to update the model and the other thread for example from email is trying to update the same model simultaneously. How can we ensure that both the models update their data properly without each losing others updated data in the context.

Accepted Solutions (0)

Answers (1)

Answers (1)

arvind-kumar_avinash
Active Contributor
0 Kudos

Please note that Models are not thread safe. If the model is being processed by multiple threads, you can synchronize access to the setters by using SessionService.

neha_gupta03
Associate
Associate
0 Kudos

We can synchronize access to setters but what if one thread is updating one attribute of model like email and other thread is updating different attribute like password and they are both trying to do modelservice.save. Then how setters synchronization will work here.

arvind-kumar_avinash
Active Contributor
0 Kudos

You can use lock(PK itemPK) method of ModelService.