In my application I have 2 @Async
methods: one for auditing purposes and another for updation of some maps in 2 entirely different beans, called from different beans but at same time. One from Audit listener and other from a controller.
My problem is that both of them run in a single thread, i.e first audit runs and then in the same thread those maps are created. So, if audit throws some exception, maps wont be created, or maps throw an error, audit wont get recorded.
Is there any way, I can have these 2 methods run in different Async threads.
Method1:
@Async(value="myExecutor")
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void regenerateZoneMapAsync(DemandSource ds) {
System.out.println("\n\n********************Current Thread in Async Class*****************" + Thread
.currentThread());
regenerateZmFilesByDs(ds);
System.out.println("\n\n*********Current Thread********" + Thread.currentThread());
}
Method2:
@Async(value="myExecutor")
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void callAudit(DemandSource ds) {
System.out.println("\n\n************Current Thread in Audit Class*********" + Thread
.currentThread());
callAudit(ds);
System.out.println("\n\n***********Current Thread********" + Thread.currentThread());
}
println has been added for my own clarity, to know which thread is been executed. I am new to both, multithreading and Spring.
My config class has
<task:annotation-driven executor="myExecutor"/>
<task:executor id="myExecutor" pool-size="5"/>
After adding above configuration with @Async(value="myExecutor")
my code has stopped working altogether, By this I mean,bean in which regenerateZoneMapAsync()
has been defined, is not called from my calling bean, some proxy issue arises.
Edit:
One thing that comes in my mind is can it be possible that Audit thread completes its processing and send the thread back to pool, and then map picks the same thread and starts its processing.
Basically I want that if audit throws any error, and roll backs map updation should still happen.