* Called by the {@link Scheduler} when a {@link Trigger}
* fires that is associated with the Job.
* </p>
*
* <p>
* The implementation may wish to set a
* {@link JobExecutionContext#setResult(Object) result} object on the
* {@link JobExecutionContext} before this method exits. The result itself
* is meaningless to Quartz, but may be informative to
* {@link JobListener}s or
* {@link TriggerListener}s that are watching the job's
* execution.
* </p>
*
* @throws JobExecutionException
* if there is an exception while executing the job.
*/
void execute(JobExecutionContext context)
throws JobExecutionException;
}
public class ClosePayJob implements Job{
public void execute(JobExecutionContext context) throws JobExecutionException{
//业务逻辑
}
}
复制代码
3.2 JobDetail
Quartz框架在每次执行Job时,都会重新创建一个Job对象实例,所以它需要Job类的信息以及其他相关信息,以便能够在运行时通过newInstance()的反射机制实例化Job。因此需要通过一个类来描述Job的实现类及其它相关的静态信息,比如Job名字、描述、关联监听器等信息。JobDetail接口包含了能够创建Job类的信息载体,用来保存任务的详细信息。如下代码定义
[code]public interface JobDetail extends Serializable, Cloneable { public JobKey getKey(); /** * * Return the description given to the Job instance by its * creator (if any). *
* * @return null if no description was set. */ public String getDescription(); /** * * Get the instance of Job that will be executed. *
*/ public Class