Job-scoped resources and thread safety

Many system and application resources are available only within a defined job. When writing a multithreaded application or service, you must evaluate your use of job-scoped resources. The use of these resources must not conflict with or negatively affect other threads in the process.

Some resources (open database files, for example) are scoped to the activation group. For the purposes of this discussion, resources that are scoped to the activation group must be treated with the same considerations as job-scoped resources. All of the threads that use the activation group use these resources.

Your application can use appropriate synchronization techniques if threads in your application modify these resources when other threads are using them. You need to ensure a consistent view of the resources between your threads.

Here are some of the common job-scoped or activation-group-scoped resources:

  • Heap, static, and global storage

    The most commonly shared resource. For more information, see Storage usage and threaded applications.

  • Open files

    After you open a file, threads in a process can directly share integrated file system files and database files by passing the file handle pointer or file descriptor number to another thread. The working directory is always scoped to the process.

  • Locales

    The locale of an application is an activation group resource. All threads share the locale. Changing the locale affects other threads with regard to collating sequences or other locale information.

  • Coded character set identifier

    Changing the coded character set identifier (CCSID) of a job affects the current data translation or representation of all threads in that job.

  • Environment variables

    Your application commonly uses environment variables for configuration and optional behavior. All the threads in the job share these environment variables.