How to keep access to java objects outside of the scope of a single Java Action
I'm looking to integrate a external java library which needs multiple related Java Actions to be executed in a microflow. (think of Start, Continue, Stop Actions) However, when a single Java Action is executed from the microflow, by default all java objects used within the Action are no longer available to the microflow. What I need is that for example the 'Stop' Action has access to the java object that was instantiated earlier by the external java library during the "Start' action. Note that these java objects are created from an external library, so they can contain complex states, behavior, hold other objects, lists, et cetera. Therefore remodeling these to non-persistent Mendix entities to keep only some if its data available within the scope of the microflow is not feasible. Is there a way to keep the java objects created by the library stored within the scope/session of a microflow, so that any related Java Actions that are called later on in this microflow can pick them up again? Thanks!
You can use IContext:getData to get a map of objects bound to the current context. You can also use that to place data.
Make the variables static. This way they will stay in memory until you delete them manually or the program shuts down.
In the generated java action code there are two places where you can add code, one is within a function, and the other one is at the end of the file. In the latter you can add static variables.