private static Method method = null;
public void execute(JobExecutionContext execution) throws JobExecutionException {
MessageEndpoint endpoint = null;
try {
JobDataMap jobDataMap = execution.getJobDetail().getJobDataMap();
Data data = Data.class.cast(jobDataMap.get(Data.class.getName()));
Job job = data.job;
endpoint = (MessageEndpoint) job;
if (null == method) {
method = Job.class.getMethod("execute", JobExecutionContext.class);
}
endpoint.beforeDelivery(method);
job.execute(execution);
} catch (NoSuchMethodException e) {
throw new IllegalStateException(e);
} catch (ResourceException e) {
throw new JobExecutionException(e);
} catch (Throwable t) {
throw new JobExecutionException(new Exception(t));
} finally {
if (null != endpoint) {
try {
endpoint.afterDelivery();
} catch (ResourceException e) {
throw new JobExecutionException(e);
}
}
}