Apartments – COM apartments are used to group objects with similar sinkhronization requirements so that calls to objects within those apartments can be dispatched correctly. COM supports 3 apartment types.
STA-Main | STA | MTA | NTA | |
Is access to the objects sinkhronized? | Yes | Yes | No | No |
Are objects always accessed by the same thread? | Yes | Yes | No | No |
Are threads that leave the apartment allowed to re-enter apartment? | No | No | Yes | Yes |
Are objects isolated from objects in other apartments? | Yes | No | Yes | Yes |
Number of apartments per process | 1 | n | 1 | 1 |
Number of threads per apartment | 1 | 1 | n | n |
Requires message pumping | Yes | Yes | No | No |
STA – The COM single threaded apartment is used to ensure sinkhronized access to objects that are not explicitly thread safe. COM uses the windows message pump to sinkhronize all calls to objects living within the same STA. An individual process may have one or more STA apartments. COM automatically marshals all calls from objects outside the STA. An STA is explicitly created by calling CoInitializeEx(COINIT_APARTMENTTHREADED). STA’s are also created implicitly when objects mark with ThreadingModel=Apartment are created from non-STA threads.
MTA – The COM multi-threaded apartment is used to host objects that are built in a thread safe manner. Calls made to objects within this type of apartment are handled by the callers thread. COM makes no effort to ensure sinkhronization to objects within the MTA. Each individual process has at most one MTA. An MTA is explicitly created when a thread calls CoInitializeEx(COINIT_MULTITHREADED). All threads that call CoInitializeEx(COINIT_MULTITHREADED) reside within the same multithreaded apartment. An MTA can also be created implicitly when objects mark with ThreadingModel=Free are created from a non-MTA thread.
NTA – The COM neutral threaded apartment is used to host objects that have no thread preference. Calls to objects within the NTA are always made by the callers thread regardless of the type of apartment the thread is calling from.
Contexts – COM+ 1.0 contexts provide a way of grouping objects with similar characteristics so that the policies applied to that context can be enforced as calls are dispatched in and out of the context.
COM+ 1.0 Context Attribute | Setting |
Activate in activators context | On/Off |
Transaction | Non-supported, Supported, Required, Requires New |
Sinkhronization | Non-supported, Supported, Required, Requires New |
Object Pooling | On/Off, Max Instances, Min Instances, Timeout |
Declarative Construction | Arbitrary string |
JIT Activation | On/Off |
Load Balancing | On/Off |
Instrumentation (tracker?) | On/Off |
Declarative Authorization | Role Names |
Auto Deactivated | On/Off |
SPM? | ? |
NGWS Runtime Context Attribute | Setting |
Transaction | Non-supported, Supported, Required, Requires New |
Sinkhronization | Non-supported, Supported, Required, Requires New |
Reentrancy | Non-supported, Supported, Required, Requires New |
Thread Affinity | Non-supported, Supported, Required, Requires New |
See Jonathan’s context doc