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 them.

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

Some of the common job-scoped or activation group-scoped resources are as follows:
  • Heap, static, and global storage:

    The most commonly shared resource. For more information, see the section about storage usage.

  • Open files:

    After you open a file, threads in a process can directly share integrated file system file 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 them.