Issue
I have event listener which is annotated @async and use SimpleAsyncTaskExecutor for generate new thread with set concurrencyLimit. What happen if in the same time I will publish event exceeds concurrencyLimit? It will be ignore or just will be wait wait for free executor? If it wait, will it block main thread which published the event?
Unfortunate I'm not able to simulate this situation.
Solution
The execute()
method, before creating the new thread, uses class ConcurrencyThrottleSupport
to handle the concurrency limit; this class uses wait/notify logic to block the calling thread if the limit has been reached. Before blocking the caller this class logs a debug message.
As its names suggests, this executor is quite simple. A ThreadPoolTaskExecutor
is a better choice: it reuses threads and let you choose what to do when you reach the limit by definining a RejectedExecutionHandler
.
Answered By - Pino
Answer Checked By - Cary Denson (JavaFixing Admin)