Labels

Thursday, September 23, 2010

Concurrency Problems - Scenarios


Before reading this post, recommended would be read these two post  - InstancingMode & ConcurrencyMode first.
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'.


InstancingMode.PerSession – Here we'll cover only Single & Multiple Thread Concurrency mode.

PerSession – Single Thread – Has Concurrency Problems

·         In case of Single Thread – there are three cases.
o    Shared 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.
o    Separate 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.
o    Common 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.
The soultion would be to apply 'Manual Synchronization'.

PerSession – Multi Thread - Manual Synchronization
PerSession – Multi Thread - Manual Synchronization

Here: 'Manual Synchronization' is applied to avoid 'Synchronization Problem'.


InstancingMode.Singleton: Here we'll cover only Single & Multiple Thread Concurrency mode.

Singleton – Single Thread – Has no Concurrency Problem

·         In case of Single Thread – there will be no 'Synchronization Problems'. Since only one thread is allowed to access.
·         Thus no 'Manual Synchronization' is required.

Singleton – Single Thread – No Concurrency Issue
Singleton – Single Thread – No Concurrency Issue
Singleton – Single Thread – No Concurrency Issue


Note: Here in all three scenarios no 'Manual Synchronization' is applied. Sinceonly one thread is allowed to access. Thus inherntily there will be no 'Synchronization Problems'.

Singleton – 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.
The soultion would be to apply 'Manual Synchronization'.

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.


Singleton – Multi Thread - Manual Synchronization
Singleton – Multi Thread - Manual Synchronization


Here: 'Manual Synchronization' is applied to avoid 'Synchronization Problem'.

Hope this helps.
 Thanks & Regards,
Arun Manglick

No comments:

Post a Comment