Share data between C or C++ components

Components in the same package can share data—that is, variable values. For example, a counter that tracks how many objects have been created for a single component could be used as a shared variable. Shared variables are organized into collections. These variables are referred to as shared because components in the same package can read and update the same data. A collection can contain any number of shared variables. Shared variables can be identified by name or by index number. Shared variables are initialized as null and are not saved when the server is shut down.

Because it is important to maintain the integrity of the shared data in shared variables, a single read or update operation on a shared variable is atomic. Atomic means that an operation on data will complete before any other operations can access that data. Multiple reads and updates on any number of shared variables in a single collection can be synchronized by locking that collection.

NoteYou cannot use shared variables in components that are configured for automatic failover, because these components cannot use local shared resources. See “Component properties: Transactions” for more information. If you need to share data, you can store shared data in a remote database.

To share data between components, you must include the jagpublic.h file in the C source file.