@ -116,6 +116,7 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
* @param runMode run mode
* @param timeout timeout
* @param startParams the global param values which pass to new process instance
* @param expectedParallelismNumber the expected parallelism number when execute complement in parallel mode
* @return execute process instance code
* /
@Override
@ -125,7 +126,7 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
TaskDependType taskDependType , WarningType warningType , int warningGroupId ,
RunMode runMode ,
Priority processInstancePriority , String workerGroup , Integer timeout ,
Map < String , String > startParams ) {
Map < String , String > startParams , Integer expectedParallelismNumber ) {
Map < String , Object > result = new HashMap < > ( ) ;
// timeout is invalid
if ( timeout < = 0 | | timeout > MAX_TASK_TIMEOUT ) {
@ -162,7 +163,7 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
* /
int create = this . createCommand ( commandType , processDefinitionId ,
taskDependType , failureStrategy , startNodeList , cronTime , warningType , loginUser . getId ( ) ,
warningGroupId , runMode , processInstancePriority , workerGroup , startParams ) ;
warningGroupId , runMode , processInstancePriority , workerGroup , startParams , expectedParallelismNumber ) ;
if ( create > 0 ) {
processDefinition . setWarningGroupId ( warningGroupId ) ;
@ -489,7 +490,7 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
String startNodeList , String schedule , WarningType warningType ,
int executorId , int warningGroupId ,
RunMode runMode , Priority processInstancePriority , String workerGroup ,
Map < String , String > startParams ) {
Map < String , String > startParams , Integer expectedParallelismNumber ) {
/ * *
* instantiate command schedule instance
@ -534,7 +535,6 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
end = DateUtils . getScheduleDate ( interval [ 1 ] ) ;
}
}
// determine whether to complement
if ( commandType = = CommandType . COMPLEMENT_DATA ) {
runMode = ( runMode = = null ) ? RunMode . RUN_MODE_SERIAL : runMode ;
@ -546,21 +546,31 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
return processService . createCommand ( command ) ;
} else if ( runMode = = RunMode . RUN_MODE_PARALLEL ) {
List < Schedule > schedules = processService . queryReleaseSchedulerListByProcessDefinitionId ( processDefineId ) ;
List < Date > listDate = new LinkedList < > ( ) ;
LinkedLi st < Date > listDate = new LinkedList < > ( ) ;
if ( ! CollectionUtils . isEmpty ( schedules ) ) {
for ( Schedule item : schedules ) {
listDate . addAll ( CronUtils . getSelfFireDateList ( start , end , item . getCrontab ( ) ) ) ;
}
}
if ( ! CollectionUtils . isEmpty ( listDate ) ) {
// loop by schedule date
for ( Date date : listDate ) {
cmdParam . put ( CMDPARAM_COMPLEMENT_DATA_START_DATE , DateUtils . dateToString ( date ) ) ;
cmdParam . put ( CMDPARAM_COMPLEMENT_DATA_END_DATE , DateUtils . dateToString ( date ) ) ;
int effectThreadsCount = expectedParallelismNumber = = null ? listDate . size ( ) : Math . min ( listDate . size ( ) , expectedParallelismNumber ) ;
logger . info ( "In parallel mode, current expectedParallelismNumber:{}" , effectThreadsCount ) ;
int chunkSize = listDate . size ( ) / effectThreadsCount ;
listDate . addFirst ( start ) ;
listDate . addLast ( end ) ;
for ( int i = 0 ; i < effectThreadsCount ; i + + ) {
int rangeStart = i = = 0 ? i : ( i * chunkSize ) ;
int rangeEnd = i = = effectThreadsCount - 1 ? listDate . size ( ) - 1
: rangeStart + chunkSize + 1 ;
cmdParam . put ( CMDPARAM_COMPLEMENT_DATA_START_DATE , DateUtils . dateToString ( listDate . get ( rangeStart ) ) ) ;
cmdParam . put ( CMDPARAM_COMPLEMENT_DATA_END_DATE , DateUtils . dateToString ( listDate . get ( rangeEnd ) ) ) ;
command . setCommandParam ( JSONUtils . toJsonString ( cmdParam ) ) ;
processService . createCommand ( command ) ;
}
return listDate . size ( ) ;
return effectThreadsCount ;
} else {
// loop by day
int runCunt = 0 ;