@ Override public void execute ( Runnable task ) { // count a new task in process tasksInProcess . incrementAndGet ( ) ; try { super . execute ( task ) ; } catch ( RuntimeException e ) { // specifically handle RejectedExecutionException tasksInProcess . decrementAndGet ( ) ; throw e ; } catch ( Error e ) { tasksInProcess . decrementAndGet ( ) ; throw e ; } }
Before calling super s version of this method the amount of tasks which are currently in process is first incremented .