Caching the Java Class

When the Cache Constructed Class check box is selected on the Advanced tab, all instances of the same Java method activity share the same Java object. For example, each process instance that executes this Java Method activity shares the same instance of the class.

Also, if this activity is executed multiple times in a loop, each execution of this activity uses the same cached instance of the object. Sharing a cached class illustrates multiple processes and Java Methods in a group all sharing the same Java class.

Warning: If you choose to cache the constructed instance of the class, the same Java object is shared by Java Method activities that invoke methods on the class. Therefore, be aware of potential concurrency issues, if your class or its methods are not threadsafe.

Figure 89: Sharing a cached class

However, different instances of a Java Method activity that invoke methods on the same class do not share the instance of the object. For example, Different Java Method activities in the same process do not share the class illustrates two Java Method activities in the same process definition, each executing different methods on the same Java object. However, each of these Java Method activities operate on their own instances of the inv class, if they both select the Cache Constructed Class check box.

Figure 90: Different Java Method activities in the same process do not share the class

In the process definition illustrated in Different Java Method activities in the same process do not share the class, for each process instance that is created, each time the inv.CheckInventory activity executes, it shares one instance of the inv object that has been cached. Similarly, each time the inv.DecreaseInv activity executes, it shares the instance of the inv object that the activity has cached. However, the inv.CheckInventory and inv.DecreaseInv activities do not share their cached Java objects with each other.