Labels

Thursday, September 23, 2010

Concurrency Problems - Scenarios

These two post discuss wbout various scenarios lying under different variants of each mode.

But here in this post, I tried discussing only those that are having the Concurrency Problems.

InstancingMode.PerCall – Has Concurrency Problems.

Ideally in PerCall - Concurrency is not a concern. This is true with any Concurreny mode – Single/Renetrant/Multiple - Since new service object is assigned for each call.

However even being Per Call, this does not preclude them from sharing Business Objects or Cached Data across service operations.

These scenarios have the possibility of Concurrency.

PerCall – Sharing Cache Object

PerCall – Sharing Business/Data Object

PerCall – Sharing Business/Data Object

Note: Here all three scenarios have the 'Synchronization Problem'.

Solution:

·The Concurrency problem can be avoided by having 'Manual Synchronization' in place.· Implementing manual synchronization will make sure that, if one request is accessing the shared 'Cache/Business/Data' object, no other request will be having the access at the same time.·Thus avoiding Concurrency problem.

PerCall – Sharing Cache Object –

Manual Synchronization

PerCall – Sharing Business/Data Object –

Manual Synchronization

PerCall – Sharing Business/Data Object –

Manual Synchronization

Note: Here in all three scenarios 'Manual Synchronization' is applied to avoid 'Synchronization Problem'.

oShared State Level at Service Object (Fig 1)– At this level - there will be no 'Synchronization Problems' as only Single thread has access at a time. Thus no 'Manual Syncronization' will be required.

oSeparate Business Objects – Per Service Instance (Fig2) - At this level also - there will be no 'Synchronization Problems' as only Single thread has access at a time. Thus no 'Manual Syncronization' will be required.

oCommon Business Objects – All Service Instances (Fig 3)– Here there will be 'Synchronization Problems'. Thus here the 'Manual Syncronization' will be required.

Fig 1: PerSession – Single Thread – No Concurrency Issue

Fig 2: PerSession – Single Thread – Has Concurrency Issue

Solution: For Fig2.

·The Concurrency problem can be avoided by having 'Manual Synchronization' in place.· Implementing manual synchronization will make sure that, if one request is accessing the shared 'Cache/Business/Data' object, no other request will be having the access at the same time.·Thus avoiding Concurrency problem.

Soution for Fig3 – Using Manual Synchronization

PerSession – Multiple Thread - Has Concurrency Problems

In case of Multiple Thread – There will be the 'Synchronization Problems'. Reason - Multiple thread are allowed to access at same time.