本文整理匯總了Java中org.quartz.JobExecutionContext.setResult方法的典型用法代碼示例。如果您正苦於以下問題:Java JobExecutionContext.setResult方法的具體用法?Java JobExecutionContext.setResult怎麽用?Java JobExecutionContext.setResult使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.quartz.JobExecutionContext
的用法示例。
在下文中一共展示了JobExecutionContext.setResult方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: execute
import org.quartz.JobExecutionContext; //導入方法依賴的package包/類
public void execute(JobExecutionContext context)
throws JobExecutionException {
JobDataMap data = context.getMergedJobDataMap();
String command = data.getString(PROP_COMMAND);
String parameters = data.getString(PROP_PARAMETERS);
if (parameters == null) {
parameters = "";
}
boolean wait = true;
if(data.containsKey(PROP_WAIT_FOR_PROCESS)) {
wait = data.getBooleanValue(PROP_WAIT_FOR_PROCESS);
}
boolean consumeStreams = false;
if(data.containsKey(PROP_CONSUME_STREAMS)) {
consumeStreams = data.getBooleanValue(PROP_CONSUME_STREAMS);
}
Integer exitCode = this.runNativeCommand(command, parameters, wait, consumeStreams);
context.setResult(exitCode);
}
示例2: runCommand
import org.quartz.JobExecutionContext; //導入方法依賴的package包/類
private void runCommand(JobExecutionContext context) throws IOException, InterruptedException {
ProcessBuilder pb = new ProcessBuilder();
setEnvironments(pb);
Path output = setOutputs(pb);
pb.command(getCommand(getJob().getCommand()));
try {
Process process = pb.start();
int exitCode = process.waitFor();
context.setResult(JobResult.builder().exitValue(exitCode).tmpFile(output).build());
} catch (Exception e) {
output.toFile().delete();
throw e;
}
}
示例3: execute
import org.quartz.JobExecutionContext; //導入方法依賴的package包/類
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
Date startDate = new Date();
LOG.debug("methodInvokeJob start : " + DateUtils.formart(startDate));
long startTime = startDate.getTime();
JobDataMap jobDataMap = context.getMergedJobDataMap();
//Object methodInvokerObj = jobDataMap.get("methodInvoker");
Object jobClassObj = jobDataMap.get("jobClass");
Object constructorArgumentsObj = jobDataMap.get("constructorArguments");
Object jobClassMethodNameObj = jobDataMap.get("jobClassMethodName");
Object jobClassMethodArgsObj = jobDataMap.get("jobClassMethodArgs");
try {
String jobClass = (String) jobClassObj;
Object[] constructorArguments = (Object[]) constructorArgumentsObj;
String jobClassMethodName = (String) jobClassMethodNameObj;
Object[] jobClassMethodArgs = (Object[]) jobClassMethodArgsObj;
Object jobBean;
LOG.debug("methodInvokeJob jobClass:" + jobClass);
LOG.debug("methodInvokeJob jobClassMethodName:" + jobClassMethodName);
QuartzBeanManagerFacade quartzBeanManagerFacade = QuartzBeanManagerFacade.getInstance();
if (constructorArguments != null && constructorArguments.length > 0) {
jobBean = quartzBeanManagerFacade.getBean(jobClass, constructorArguments);
} else {
jobBean = quartzBeanManagerFacade.getBean(jobClass);
}
MethodInvoker methodInvoker = new MethodInvoker();
methodInvoker.setTargetMethod(jobClassMethodName);
methodInvoker.setArguments(jobClassMethodArgs);
methodInvoker.setTargetObject(jobBean);
boolean prepared = methodInvoker.isPrepared();
if (!prepared) {
methodInvoker.prepare();
}
Object result = methodInvoker.invoke();
context.setResult(result);
Date endDate = new Date();
long endTime = endDate.getTime();
LOG.debug("methodInvokeJob end : " + DateUtils.formart(endDate) + "," + (endTime - startTime));
} catch (Exception e) {
LOG.error("MethodInvokeJob exception message:" + e.getMessage(), e);
e.printStackTrace();
throw new JobExecutionException(e);
}
}