@@ -44,6 +44,8 @@ public class WrappedScheduledExecutorService extends ScheduledThreadPoolExecutor
4444
4545 final Logger logger = LoggerFactory .getLogger (WrappedScheduledExecutorService .class );
4646
47+ private static final Duration DEFAULT_TIMEOUT = Duration .ofMillis (5000 );
48+
4749 public WrappedScheduledExecutorService (int corePoolSize , ThreadFactory threadFactory ) {
4850 super (corePoolSize , threadFactory );
4951 }
@@ -53,8 +55,6 @@ public WrappedScheduledExecutorService(int corePoolSize, ThreadFactory threadFac
5355 * it outputs a log message with the stack trace from whence the task was originally scheduled.
5456 */
5557 private abstract class TimedAbstractTask {
56- private static final Duration DEFAULT_TIMEOUT = Duration .ofMillis (5000 );
57-
5858 private final Exception stackTraceHolder ;
5959 private Instant timeout ;
6060
@@ -148,23 +148,27 @@ protected void afterExecute(@Nullable Runnable r, @Nullable Throwable t) {
148148
149149 @ Override
150150 public ScheduledFuture <?> schedule (@ Nullable Runnable runnable , long delay , @ Nullable TimeUnit unit ) {
151- return super .schedule (new TimedRunnable (runnable ), delay , unit );
151+ Runnable r = logger .isDebugEnabled () ? new TimedRunnable (runnable ) : runnable ;
152+ return super .schedule (r , delay , unit );
152153 }
153154
154155 @ Override
155156 public ScheduledFuture <?> scheduleAtFixedRate (@ Nullable Runnable runnable , long initialDelay , long period ,
156157 @ Nullable TimeUnit unit ) {
157- return super .scheduleAtFixedRate (new TimedRunnable (runnable ), initialDelay , period , unit );
158+ Runnable r = logger .isDebugEnabled () ? new TimedRunnable (runnable ) : runnable ;
159+ return super .scheduleAtFixedRate (r , initialDelay , period , unit );
158160 }
159161
160162 @ Override
161163 public ScheduledFuture <?> scheduleWithFixedDelay (@ Nullable Runnable runnable , long initialDelay , long delay ,
162164 @ Nullable TimeUnit unit ) {
163- return super .scheduleWithFixedDelay (new TimedRunnable (runnable ), initialDelay , delay , unit );
165+ Runnable r = logger .isDebugEnabled () ? new TimedRunnable (runnable ) : runnable ;
166+ return super .scheduleWithFixedDelay (r , initialDelay , delay , unit );
164167 }
165168
166169 @ Override
167170 public <V > ScheduledFuture <V > schedule (@ Nullable Callable <V > callable , long delay , @ Nullable TimeUnit unit ) {
168- return super .schedule (new TimedCallable <V >(callable ), delay , unit );
171+ Callable <V > c = logger .isDebugEnabled () ? new TimedCallable <>(callable ) : callable ;
172+ return super .schedule (c , delay , unit );
169173 }
170174}
0 commit comments