At any given time, a session-scoped or request-scoped component might have multiple instances. For example, a session-scoped component instance might exist for each user logged on to the site.
When a component instance is created, the Oracle Commerce Platform does not create objects for its properties. In order to minimize memory use, new component properties are set as pointers to existing instances of those objects. Consequently, be careful how you set properties of a session-scoped or request-scoped component; changing the value of a property is liable to affect other component instances, depending on the property data type:
You can safely set the value of an immutable object such as a
String
property. In this case, the system creates aString
object and sets the property to it. The property has a unique reference to theString
object which other component instances cannot affect.If you change the value of a mutable object such as an array, always replace the object rather than modify the object in place.
For example, given an array property myArray
String[]
set to {"a", "b", "c"}
, you should change its last element by creating an array with the desired change and setting the property to it:
setMyArray(new String[] {"a", "b", "z"}
Conversely, the following code incorrectly modifies the array in place, and is liable to affect other component instances:
String[] arr = getMyArray()
arr[2] = "z";