ckangtai

AX2009 批处理作业中使用多线程---独立任务模式

每个工单独立一个任务。

 


Class

/*
独立任务模式
*/
class DemoBatchIndividualTasks extends RunBaseBatch
{
     str 20 SalesOrder;
    #define.CurrentVersion(1)
    #localmacro.CurrentList
        SalesOrder
    #endmacro
}
 
public container pack()
{
    return [#CurrentVersion, #CurrentList];
}

public static DemoBatchIndividualTasks construct(str _SalesOrder)
{
    DemoBatchIndividualTasks  c;
    ;
    c = new DemoBatchIndividualTasks();
    c.parmSalesOrder(_SalesOrder);
    return c;
}

public boolean unpack(container packedClass)
{
    Version version = RunBase::getVersion(packedClass);
    switch(version)
    {
        case #CurrentVersion:
            [version,#CurrentList] = packedClass;
            break;
        default:
            return false;
    }
    return true;
}
 
private void parmSalesOrder(str _SalesOrder)
{
    SalesOrder= _SalesOrder;
}

//Single Work item per thread
void run()
{
    SalesTable                          salesTable;
    SalesFormLetter                     formletter;
    Map                                 SalesMap;
     
    select * from salesTable
        where salesTable.salesId == SalesOrder &&
              salesTable.documentStatus == DocumentStatus::none;
 
    if (salesTable)
    {
        formletter = SalesFormLetter::construct(DocumentStatus::Invoice);
        formletter.getLast();
        formletter.resetParmListCommonCS();
        formletter.allowEmptyTable(formletter.initAllowEmptyTable(true));
        SalesMap = new Map(Types::Int64,Types::Record);
        SalesMap.insert(salesTable.recid,salesTable);
//        formletter.parmDataSourceRecordsPacked(SalesMap.pack());
//        formletter.createParmUpdateFromParmUpdateRecord(SalesFormletterParmData::initSalesParmUpdateFormletter(DocumentStatus::Invoice, FormLetter.pack()));
        formletter.showQueryForm(false);
        formletter.initLinesQuery();
        formletter.update(salesTable, systemDateGet(), SalesUpdate::All, AccountOrder::None, false, false);
    }
}

public void new()
{
    super();
}

 

Job 测试

static void scheduleDemoIndividualTasksJob(Args _args)
{
    BatchHeader                     batchHeader;
    DemoBatchIndividualTasks        demoBatchIndividualTasks;
    BatchInfo                       batchInfo;
    SalesTable                      salesTable;

    SalesId                         _SalesIdFrom,_SalesIdTo;
    ;


    _SalesIdFrom = "SSO000001";
    _SalesIdTo = "SSO001000";
    ttsBegin;
    select count(RecId) from salesTable
        where salesTable.salesId >= _SalesIdFrom &&
            salesTable.salesId <= _SalesIdTo && salesTable.documentStatus == DocumentStatus::none; if (salesTable.recid > 0)
    {
        batchHeader = BatchHeader::construct();
        batchHeader.parmCaption(strFmt('Batch job for demoBatchIndividualTasks'));

        while select * from salesTable
            where salesTable.salesId >= _SalesIdFrom &&
                salesTable.salesId <= _SalesIdTo &&
                salesTable.documentStatus == DocumentStatus::none
        {
            /* Each task is created to process a single work item (in this case a single sales Order)*/
            demoBatchIndividualTasks = DemoBatchIndividualTasks::construct( salesTable.salesid);
            batchInfo = demoBatchIndividualTasks.batchInfo();
            BatchInfo.parmCaption('Invoicing : '+salesTable.salesid);

            batchInfo.parmGroupId("COUNTING");

            batchHeader.addTask(demoBatchIndividualTasks);
        }
        batchHeader.save();
    }
    ttsCommit;
    info('Done');
}

/*
独立任务模式

假设,我们处理10万条记录

#创建任务    #批处理线程(在我的测试服务器)    #可并行执行的并行任务
100,000      10                                 10

一旦前10个任务完成,批处理框架将加载后10个任务并执行它们,在这种情况下
,它可以加载10,000或更多次。
*/

  

posted on 2018-09-12 09:10  ckangtai  阅读(340)  评论(0编辑  收藏  举报

导航