if (workListener != null) {
long duration = System.currentTimeMillis() - creationTime;
if (duration > timeout) {
// This can occur only in case of scheduleWork
logger.warn("REJECTED: duration= {0}", duration);
workListener.workRejected(new WorkEvent(this, WorkEvent.WORK_REJECTED, work, null));
return;
}
workListener.workStarted(new WorkEvent(this, WorkEvent.WORK_STARTED, work, null));
}
// Setup ExecutionContext
Xid xid = null;
if (executionContext != null) {
xid = executionContext.getXid();
if (xid != null) {
long txtimeout = executionContext.getTransactionTimeout();
try {
if (txtimeout != WorkManager.UNKNOWN) {
this.transactionComponent.begin(xid, txtimeout);
} else {
this.transactionComponent.begin(xid);
}
} catch (NotSupportedException e) {
throw new WorkException("Error starting a new transaction", e);
} catch (SystemException e) {
throw new WorkException("Error starting a new transaction", e);
}
}
}
try {
work.run();
// Notify the listener that the work is completed.
if (workListener != null) {
workListener.workCompleted(new WorkEvent(this, WorkEvent.WORK_COMPLETED, work, null));
}
} catch (Exception e) {
if (workListener != null) {
workListener.workCompleted(new WorkEvent(this, WorkEvent.WORK_COMPLETED, work, null));
}
throw new WorkCompletedException(e);
} finally {
if (xid != null) {
this.transactionComponent.clearThreadTx();