Quarts示例通常会这样做:
JobDetail job = newJob(PrintMessageJob.class)
如何创建在运行时定义了param的作业?这样的事情会很好但不允许:
JobDetail job = newJob( new PrintMessageJob("my message") );
由于
答案 0 :(得分:2)
您必须做的是以下内容。
JobDetail job = newJob(PrintMessageJob.class)
.usingJobData("message", "my message")
.build();
public class PrintMessageJob implements Job {
public PrintMessageJob() {
}
public void execute(JobExecutionContext context) throws JobExecutionException
{
JobDataMap dataMap = context.getJobDetail().getJobDataMap();
String message = dataMap.getString("message");
...
}
}