Section 8.1. Instance Management and Concurrency


8.1. Instance Management and Concurrency

Service-instance thread safety is closely related to the service-instancing mode. A per-call service instance is thread-safe by definition because each call gets its own dedicated instance. That instance will only be accessible by its assigned worker thread and therefore will have no need for synchronization because no other threads will be accessing it. However, a per-call service is typically state-aware. The state store can also be in-memory resources such as static variables. The state store can be subject to multithreaded access because the service can sustain concurrent calls. Consequently, you must synchronize access to the state store.

A per-session service does require concurrency management and synchronization. The reason is that the client may use the same proxy and yet dispatch calls on multiple client-side threads to the service. A singleton service is even more susceptible to concurrent access, and must have synchronized access. The singleton has some in-memory state that all clients implicitly share. On top of the possibility for dispatching calls on multiple threads as with a per-session service, a singleton may simply have multiple clients in different execution contexts, each using its own thread to call the service. All these calls will enter the singleton on different threads from the thread pool, hence the need for synchronization.




Programming WCF Services
Programming WCF Services
ISBN: 0596526997
EAN: 2147483647
Year: 2004
Pages: 148
Authors: Juval Lowy

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net