Fix future cancelation (DataDog/dd-trace-java#1555)
MODIFY
utils/thread-utils/src/main/java/io/opentelemetry/auto/common/exec/CommonTaskExecutor.java
utils/thread-utils/src/main/java/io/opentelemetry/auto/common/exec/CommonTaskExecutor.java
@@ -80,8 +80,7 @@ public final class CommonTaskExecutor extends AbstractExecutorService {
try {
final PeriodicTask<T> periodicTask = new PeriodicTask<>(task, target);
final ScheduledFuture<?> future =
- executorService.scheduleAtFixedRate(
- new PeriodicTask<>(task, target), initialDelay, period, unit);
+ executorService.scheduleAtFixedRate(periodicTask, initialDelay, period, unit);
periodicTask.setFuture(future);
return future;
} catch (final RejectedExecutionException e) {

MODIFY
utils/thread-utils/src/test/groovy/io/opentelemetry/auto/common/exec/PeriodicSchedulingTest.groovy
utils/thread-utils/src/test/groovy/io/opentelemetry/auto/common/exec/PeriodicSchedulingTest.groovy
@@ -87,10 +87,11 @@ class PeriodicSchedulingTest extends AgentSpecification {
!CommonTaskExecutor.INSTANCE.isShutdown()
when:
- CommonTaskExecutor.INSTANCE.scheduleAtFixedRate(task, null, 10, 10, MILLISECONDS, "test")
+ def future = CommonTaskExecutor.INSTANCE.scheduleAtFixedRate(task, null, 10, 10, MILLISECONDS, "test")
Thread.sleep(11)
then:
+ future.isCancelled()
callCount.get() == 0
}
}

Fix future cancelation (DataDog/dd-trace-java#1555)