Search code examples
javaspringspring-bootinterceptorspring-aop

Is there any possible ways to get args from RejectedExecutionHandler


here I have a question.

I'm overwriting my thread pool's RejectedExecutionHandler, I want to deal with the exceeding threads which were too many for the thread pool and will be ignored by discard policy, then printing logs to show which of the thread is discarded.

I have solved how to get it done when using Explicit call like executor.submit(runnable)

But when dealing with methods annotated with@Async, it seems impossible to achieve the args though I can see them in task's arg2 like this: enter image description here

So far I have no idea how to get these 2 args, and once the threads is too many to my thread pool, I have no idea to check which thread with which parameters was discarded by

I can only get a thread id and thread name ... and that's not I want.

healp me please! thanks a lot!


Solution

  • Thanks a lot for @kriegaex's tips!

    So far I Have Solved this problem.

    Here is my solution in github of how to customize a RejectedExecutionHandler and print the key logs of the tasks which were discarded by the already full thread pool.

    So far, it supports @Async, normal Runnable and Callable, and customized tasks implements my customized interface IRejectFreeExecutable, and also Runnable and Callable invoked in anonymous ways.

    the test code is in AsyncController

    I have not consider the situations if Runnable or Callable was wrapped by FutureTask or something else.

    I think that problem can be solved based on these existing solution.