I'm trying to work with an @TransactionalEventListener (Spring 4.3) that will run an event after a transaction completes.
However, I've got my own ApplicationEventMulticaster that I'm building and using a ThreadPoolTaskExecutor for.
The docs for SimpleApplicationEventMulticaster state:
/**
* Set a custom executor (typically a {@link org.springframework.core.task.TaskExecutor})
* to invoke each listener with.
* <p>Default is equivalent to {@link org.springframework.core.task.SyncTaskExecutor},
* executing all listeners synchronously in the calling thread.
* <p>Consider specifying an asynchronous task executor here to not block the
* caller until all listeners have been executed. However, note that asynchronous
* execution will not participate in the caller's thread context (class loader,
* transaction association) unless the TaskExecutor explicitly supports this.
* @see org.springframework.core.task.SyncTaskExecutor
* @see org.springframework.core.task.SimpleAsyncTaskExecutor
*/
public void setTaskExecutor(Executor taskExecutor) {
this.taskExecutor = taskExecutor;
}
However, I am unable to locate an Async TaskExecutor that is transaction aware. Does something like this exist in the Java ecosystem already?
Currently, my events never get ran because the ThreadPoolTaskExecutor is not transaction aware, so it always thinks there is no current transaction - ignoring the Event Listener.