lgp
lgp

Reputation: 335

java- clarification needed on before/afterExecute method in ThreadPoolExecutor

From the doc page: Note: To properly nest multiple overridings, subclasses should generally invoke super.afterExecute at the beginning of this method.

If I had a chain of subclasses of ThreadPoolExecutor, each with an afterExecute override, putting the super.afterExecute will ensure that each afterExecute override in its respective subclass will run?

Since the original afterExecute method in ThreadPoolExecutor is empty, putting super.afterExecute in the first subclass doesn't do anything useful?

Upvotes: 1

Views: 526

Answers (1)

Bohemian
Bohemian

Reputation: 425073

Maybe, but there are situations where you could cause you problems if you do not call super.afterExecute(), because your code will still run, but the Executor may not function properly if:

  • someone (else) changes the type of Executor to one that does have code
  • a later version of the JVM changes the implementation and introduces code

Not being thorough is like a ticking time bomb that may explode one day, and it will be much harder to find the bug later on.

Upvotes: 2

Related Questions