Contexts
- A native context, which is the automatically occurring context of the application program and protected resources associated with a work request. A native context is associated with a single application task. This context always exists.
- A privately-managed context, which a resource manager creates. The resource manager owns a privately-managed context it creates, and the resource manager can switch a privately-managed context from one task to another. A privately-managed context is usually used by a work manager, which is a resource manager, like IMS™, that accepts and manages work, such as transactions, from outside the system.
Table 1 summarizes the differences between the two types of contexts.
| Difference | Native Context | Privately-Managed Context |
|---|---|---|
| Creation of context | Implicitly by the operating system | Explicitly by a resource manager |
| Association of context | Always with an application's task | Temporarily may not be associated with any task |
| Association change | Cannot change association from one application's task to another | Can change association from one application's task to another at any time. The change can even be to a work unit in a different home address space |
| Context end |
|
|
- The context ends
- The context switches from one application's task to another
When a resource manager expresses interest in a context, the system provides a context token that represents the context. The context token is unique within an MVS™ system or sysplex but is not guaranteed to be unique across a network of MVS systems.
Privately-Managed Contexts: When a resource manager that is processing transactions creates a new work request, the resource manager should create a new privately-managed context for the request. The resource manager can associate the context with the application's task that will run for the work request.
If needed, the resource manager can disassociate the privately-managed context from a task and later reassociate it with the same task or another task. By changing the associations, the resource manager can have one task that runs for many work requests, many tasks that run in series for a single work request, or both. Note that a context cannot be associated at the same time with multiple tasks.
When a task changes from processing for one work request to processing for another work request, the resource manager should switch the privately-managed contexts associated with the task.
Current Context: Every task in the system has an associated context; thus, there is always a context for a given task. When a task is created, context services provides the original (native) context for the task. A call to the Begin_Context service creates a privately-managed context, and a call to the Switch_Context service changes the current context to the privately-managed context. The native context still exists, but is not current. If a later call to the Switch_Context service disassociates the privately-managed context, the native context again becomes the current context.
If a privately-managed context associated with a task ends, the native context becomes the current context. If a task ends while there is a privately-managed context associated with it, the privately-managed context ends, followed immediately by the end of the task's native context.