You can designate a component as reusable, or persistent, so that the infrastructure does not need to create a new instance of the execution class every time the component is to be run. To designate a component as reusable, define a component property named “reusePolicy” with the value of “any” (the default value is “none”). When a component has this designation, the infrastructure may use the same class instance for multiple executions. The system is not required to reuse a class instance. This feature gives the system the flexibility to reuse a class instance if it is beneficial for performance or memory reasons. When a component has a reusePolicy of “any,” the component lifecycle is:
In this case some of the component methods are called multiple times, once for each execution of the component. Component reuse is always serial. Once the execution sequence starts (with a call to configEnvironment()), the sequence will complete, ending with postExecute(), before another call will be made to start the execution sequence again. As in the nonreuse case, the system guarantees that all calls to these methods are made one at a time and on the same JVM thread. At any time when the component instance is not in the execution sequence (for example, postExecute() was the last method called), the system may choose to call the destroy() method and remove all its references to the instance. Later the JVM may garbage collect the instance. However, in general, the system will not destroy an existing instance; it will remain persistent until the SIMULIA Execution Engine station is stopped or the Isight Gateway is closed (local Isight execution). Persistent components can be useful when the component needs to perform some long-running initialization one time (e.g., starting an external application process). Performing a long-running initialization can be done once in the initialize() method; the external application can then be used over and over again for different executions (assuming the application supports that type of usage and does not have to be restarted for each usage). Typically, the destroy() method would be used to release whatever resources were allocated in the initialize() method, such as closing and external application process. Even when a component is persistent and reusable, the system may still create multiple instances to run at the same time. For example, in the SIMULIA Execution Engine distributed execution environment a station may be requested to execute the same component for two users running different models. The system might not wait for one to complete before starting another. It may create two instances that will execute at the same time, each on their own thread. If the component cannot support multiple concurrent instances, it can limit the number of instances the system will create. For more information, see Limiting Component Instances. For a component class to be safe for this type of repeated execution, it must be serially reusable. In effect, it must “forget” everything from one execution cycle to the next. If it fails to ignore data from a prior execution, the data may “pollute” or corrupt data in a subsequent execution. In Java programming terms, the following guidelines should be followed by the component class and any classes it calls directly or indirectly:
|