Reputation: 1053
I use spring @Async annotation to execute certain tasks. At some point (maybe because the pool-size was reached) I see in the debugger that the method with @Async is called but the break point in the method is not reached. I do not know it it will be called when another @Async method is finished or it is skipped forever.
I would like to know if it is possible to trigger an exception when there are not free @Async to execute it.
In addition, how can I know how many @Async are currently used at any given time
Thanks Avi
Upvotes: 1
Views: 1990
Reputation: 11
At some point (maybe because the pool-size was reached) I see in the debugger that the method with @Async is called but the break point in the method is not reached.
Are you sure that the code fragment if not blocked by some conditional? Without a valid code sample, one can only speculate at this point.
I would like to know if it is possible to trigger an exception when there are not free @Async to execute it.
A TimeoutException is usually thrown in this case. You can modify the time out value by adding the following to your Spring config XML.
<mvc:annotation-driven>
<mvc:async-support default-timeout="180"/>
</mvc:annotation-driven>
Alternatively have a look at this answer: Providing a timeout value when using @Async for a method using Spring 3.0
In addition, how can I know how many @Async are currently used at any given time
Usually when you activate logging using e.g. sl4j inside the code executed inside an @Async method, you'll see the following output:
2017-03-10 10:27:41,910 [SimpleAsyncTaskExecutor-1] DEBUG
2017-03-10 10:27:43,282 [SimpleAsyncTaskExecutor-2] DEBUG
Hope that this helps!
Upvotes: 1