public synchronized boolean scheduleJobIfAbsent ( final String cronExpression , final QuartzJobDescription jobDescription ) throws SchedulerException { requireNonNull ( jobDescription , "jobDescription is null" ) ; if ( ifJobExist ( jobDescription . getJobName ( ) , jobDescription . getGroupName ( ) ) ) { logger . warn ( String . format ( "can not register existing job with job name: " + "%s and group name: %s" , jobDescription . getJobName ( ) , jobDescription . getGroupName ( ) ) ) ; return false ; } if ( ! CronExpression . isValidExpression ( cronExpression ) ) { throw new SchedulerException ( "The cron expression string <" + cronExpression + "> is not valid." ) ; } // TODO kunkun-tang: we will modify this when we start supporting multi schedules per flow. final JobDetail job = JobBuilder . newJob ( jobDescription . getJobClass ( ) ) . withIdentity ( jobDescription . getJobName ( ) , jobDescription . getGroupName ( ) ) . build ( ) ; // Add external dependencies to Job Data Map. job . getJobDataMap ( ) . putAll ( jobDescription . getContextMap ( ) ) ; // TODO kunkun-tang: Need management code to deal with different misfire policy final Trigger trigger = TriggerBuilder . newTrigger ( ) . withSchedule ( CronScheduleBuilder . cronSchedule ( cronExpression ) . withMisfireHandlingInstructionFireAndProceed ( ) // .withMisfireHandlingInstructionDoNothing() // .withMisfireHandlingInstructionIgnoreMisfires() ) . build ( ) ; this . scheduler . scheduleJob ( job , trigger ) ; logger . info ( "Quartz Schedule with jobDetail " + job . getDescription ( ) + " is registered." ) ; return true ; }
Only cron schedule register is supported . Since register might be called when concurrently uploading projects so synchronized is added to ensure thread safety .