
Hi folks
I have a resource intensive job which may benefit from parallel processing. This is the first time I am using this functionality.
Firstly - I am unsure whether my wording is correct. I am referring to BatchHeader.addRuntimeTask(someChildTask). I assume that the functionality enables one to run processes simultaneously.
I have studied a few examples in the standard application. Most of them are used in RunBaseBatch. Nevertheless I can use the logic with SysOperation. But they all differ very much. And many of them include recalling the host controller for each sub process (with different parameters). This does not make sense to me - it should still be the same controller, but different operations. Clarification please
My current implementation looks something like this:
final internal class XYZController extends SysOperationServiceController
{
static void main(Args _args)
{
XYZController controller = new XYZController();
controller.initializeFromArgs(_args); //class, method and execution mode specified on the menu item
controller.startOperation();
}
protected boolean canRunInNewSession()
{
//super() //do not call super
return true;
}
boolean mustGoBatch()
{
//super //do not call super
return true;
}
void run()
{
//this is where most of the examples do the "splliting".
//I do not understand this - isn't there a more logical way to do this?
//I mean we do not want to duplicate the process - which we are effectively doing here.
//We want to split the process. And then we won't be creating new controllers.
//We will be creating new Operation classes.
//nevertheless, here is the current implementation
XYZContract contract = this.getDataContractObject();
if (!contract.parmTaskPortion())
{
//if a task portion has not been assigned - then we are in the header
ttsbegin;
BatchHeader batchHeader = this.batchInfo().parmBatchHeader();
//I see a lot of examples where a runtime task is created for the original process as well
//Is that really necessary?
//XYZController controller = new XYZController();
//controller.initializeFromArgs(this.parmArgs());
//batchHeader.addRuntimeTask(controller,batchHeader.parmBatchHeaderId());
Array portionArray = returnAnArrayThatSplitsTheTaskIntoPortions;
for (int i = 1; i <= portionArray.lastIndex(); i )
{
XYZController controller = new XYZController();
controller.initializeFromArgs(this.parmArgs());
controller.parmShowDialog(false);
//I also see a lot of examples that do this:
//controller.unPack(this.pack());
//what does it do? Is it necessary?
XYZContract portionContract = controller.getDataContractObject();
portionContract.parmTaskPortion(portionArray.value(i);
batchHeader.addRuntimeTask(controller,batchHeader.parmBatchHeaderId());
//the tasks aren't dependant - no need to call batchHeader.addDependancy() ?
}
batchHeader.save();
ttscommit;
}
super();
}
}
final class XYZOperation extends SysOperationServiceBase
{
final void operation(XYZContract _contract)
{
XYZTaskPortion taskPortion = _contract.parmTaskPortion();
if (taskPortion)
{
//if we are not in the header and actually in one of the sub processes that handle a portion of the whole
this.doSomethingWithThatPortionOfTheTask(taskPortion);
}
}
private void doSomethingWithThatPortionOfTheTask(XYZTaskPortion _taskPortion)
{
//massive logic
}
}
My question is: how should parallel processing be accomplished? Should it be placed in run() in the controller? If it should, please explain.
And then as a side question - is it possible to accomplish parallel processing for non-batch processes? Because currently I need to ensure that the process goes batch, or I'll need to check whether we are in batch. I mean it will be quite nifty if an asynchronous non-batch job could also benefit from parallel processing.
Thanks for your attention.