The examples in this folder illustrate how to spawn new service threads. The code in every example is commented in detail to help the developer get a better understanding of how to work with threads in webMethods IS.
The code in every example is commented in detail to help the developer get a better understanding of how to work with threads in webMethods IS.
The following is an example scenario: Company xyz receives a purchase order.
Before the order can be sent to the backend system a few checks need to take
place (but in no particular order). These checks may include checking the
credit card number, validate the zip code, etc (all of which can be
accomplished via threads). After the checks have taken place, the results and
decide whether or not to place the order.
The pipeline is an IData object and the default implementation of IData is not thread safe. Some objects that are put into the pipeline are also not thread safe. This means that when spawning a new service you must be aware of the pipeline and the data in it that is passed to each thread. As a result there are a number of approaches to ensure that the pipeline and the data in it doesn’t get corrupted:
1. If the data each thread needs are unique subsets of each other: Create a new pipeline (e.g. 'pipelet') for each thread using IDataFactory.create() and fill it with only the data that new thread needs to work on (in our samples this approach is called copyPipelineObjects).
2. If the data each thread needs overlaps, but the data is all simple objects (no IDatas). Create a shallow clone of the pipeline using IDataUtil.clone().(in our samples this approach is called shallowClone).
3. If the data each thread needs overlaps and the data contains deeply nested complex objects, but objects can be created for relatively little cost then create a new pipeline and fill it with a copy of the newly created objects. For example, the output of xmlNodeToDocument is PO and it needs to be processed to create a PO Ack in one thread, while the PO is being mapped to an internal format on another thread. The pipeline has a lot of other objects in it that only one thread needs. Create a new ‘pipelet’ and fill it with a newly generated copy of the data by calling the generation service twice (in our samples this approach is called loadDataTwice).
4. If the data each thread needs overlap and are deeply nested complex objects that will cost a lot to create twice. Call IDataUtil.deepClone().(in our samples this approach is called deepClone).
None