How to log runnable within RejectedExecutionHandler

389 views Asked by At

I wanna to log failed runnables.

For that I consider:

public class LoggableRejectedExecutorHanlder implements RejectedExecutionHandler {
@Override
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
    ....
    log.error(" rejected task" + r);
}
...

service.submit(new Runnable() { ... public String toString() {return xxx;})

That class I'm going to use within ThreadPoolExecutor.RejectedExecutionHandler.

Unfortunately in log I see that r is a FutureTask, and my implementation of toString is not used. Within FutureTask I see that my runnable is wrapped inside private final sync property.

Is there a good way (besides reflection) for me to log within the rejectedHandler my runnable's toString?

0

There are 0 answers