Browse Source

Deprecate AsyncTaskExecutor.execute(Runnable task, long startTimeout)

Closes gh-27959
pull/28119/head
Juergen Hoeller 4 years ago
parent
commit
a71a45e719
  1. 3
      spring-context-support/src/main/java/org/springframework/scheduling/commonj/WorkManagerTaskExecutor.java
  2. 3
      spring-context-support/src/main/java/org/springframework/scheduling/quartz/SimpleThreadPoolTaskExecutor.java
  3. 3
      spring-context/src/main/java/org/springframework/scheduling/concurrent/ConcurrentTaskExecutor.java
  4. 3
      spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskExecutor.java
  5. 3
      spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskScheduler.java
  6. 20
      spring-core/src/main/java/org/springframework/core/task/AsyncTaskExecutor.java
  7. 8
      spring-core/src/main/java/org/springframework/core/task/SimpleAsyncTaskExecutor.java
  8. 3
      spring-core/src/main/java/org/springframework/core/task/TaskRejectedException.java
  9. 5
      spring-core/src/main/java/org/springframework/core/task/TaskTimeoutException.java
  10. 3
      spring-core/src/main/java/org/springframework/core/task/support/TaskExecutorAdapter.java
  11. 6
      spring-tx/src/main/java/org/springframework/jca/work/SimpleTaskWorkManager.java
  12. 12
      spring-tx/src/main/java/org/springframework/jca/work/WorkManagerTaskExecutor.java

3
spring-context-support/src/main/java/org/springframework/scheduling/commonj/WorkManagerTaskExecutor.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -171,6 +171,7 @@ public class WorkManagerTaskExecutor extends JndiLocatorSupport
} }
} }
@Deprecated
@Override @Override
public void execute(Runnable task, long startTimeout) { public void execute(Runnable task, long startTimeout) {
execute(task); execute(task);

3
spring-context-support/src/main/java/org/springframework/scheduling/quartz/SimpleThreadPoolTaskExecutor.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -76,6 +76,7 @@ public class SimpleThreadPoolTaskExecutor extends SimpleThreadPool
} }
} }
@Deprecated
@Override @Override
public void execute(Runnable task, long startTimeout) { public void execute(Runnable task, long startTimeout) {
execute(task); execute(task);

3
spring-context/src/main/java/org/springframework/scheduling/concurrent/ConcurrentTaskExecutor.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -147,6 +147,7 @@ public class ConcurrentTaskExecutor implements AsyncListenableTaskExecutor, Sche
this.adaptedExecutor.execute(task); this.adaptedExecutor.execute(task);
} }
@Deprecated
@Override @Override
public void execute(Runnable task, long startTimeout) { public void execute(Runnable task, long startTimeout) {
this.adaptedExecutor.execute(task, startTimeout); this.adaptedExecutor.execute(task, startTimeout);

3
spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskExecutor.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2021 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -340,6 +340,7 @@ public class ThreadPoolTaskExecutor extends ExecutorConfigurationSupport
} }
} }
@Deprecated
@Override @Override
public void execute(Runnable task, long startTimeout) { public void execute(Runnable task, long startTimeout) {
execute(task); execute(task);

3
spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskScheduler.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2021 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -282,6 +282,7 @@ public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport
} }
} }
@Deprecated
@Override @Override
public void execute(Runnable task, long startTimeout) { public void execute(Runnable task, long startTimeout) {
execute(task); execute(task);

20
spring-core/src/main/java/org/springframework/core/task/AsyncTaskExecutor.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -21,8 +21,7 @@ import java.util.concurrent.Future;
/** /**
* Extended interface for asynchronous {@link TaskExecutor} implementations, * Extended interface for asynchronous {@link TaskExecutor} implementations,
* offering an overloaded {@link #execute(Runnable, long)} variant with a start * offering support for {@link java.util.concurrent.Callable}.
* timeout parameter as well support for {@link java.util.concurrent.Callable}.
* *
* <p>Note: The {@link java.util.concurrent.Executors} class includes a set of * <p>Note: The {@link java.util.concurrent.Executors} class includes a set of
* methods that can convert some other common closure-like objects, for example, * methods that can convert some other common closure-like objects, for example,
@ -41,10 +40,18 @@ import java.util.concurrent.Future;
*/ */
public interface AsyncTaskExecutor extends TaskExecutor { public interface AsyncTaskExecutor extends TaskExecutor {
/** Constant that indicates immediate execution. */ /**
* Constant that indicates immediate execution.
* @deprecated as of 5.3.16 along with {@link #execute(Runnable, long)}
*/
@Deprecated
long TIMEOUT_IMMEDIATE = 0; long TIMEOUT_IMMEDIATE = 0;
/** Constant that indicates no time limit. */ /**
* Constant that indicates no time limit.
* @deprecated as of 5.3.16 along with {@link #execute(Runnable, long)}
*/
@Deprecated
long TIMEOUT_INDEFINITE = Long.MAX_VALUE; long TIMEOUT_INDEFINITE = Long.MAX_VALUE;
@ -58,7 +65,10 @@ public interface AsyncTaskExecutor extends TaskExecutor {
* @throws TaskTimeoutException in case of the task being rejected because * @throws TaskTimeoutException in case of the task being rejected because
* of the timeout (i.e. it cannot be started in time) * of the timeout (i.e. it cannot be started in time)
* @throws TaskRejectedException if the given task was not accepted * @throws TaskRejectedException if the given task was not accepted
* @see #execute(Runnable)
* @deprecated as of 5.3.16 since the common executors do not support start timeouts
*/ */
@Deprecated
void execute(Runnable task, long startTimeout); void execute(Runnable task, long startTimeout);
/** /**

8
spring-core/src/main/java/org/springframework/core/task/SimpleAsyncTaskExecutor.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -174,6 +174,7 @@ public class SimpleAsyncTaskExecutor extends CustomizableThreadCreator
* if configured (through the superclass's settings). * if configured (through the superclass's settings).
* @see #doExecute(Runnable) * @see #doExecute(Runnable)
*/ */
@SuppressWarnings("deprecation")
@Override @Override
public void execute(Runnable task) { public void execute(Runnable task) {
execute(task, TIMEOUT_INDEFINITE); execute(task, TIMEOUT_INDEFINITE);
@ -188,6 +189,7 @@ public class SimpleAsyncTaskExecutor extends CustomizableThreadCreator
* @see #TIMEOUT_IMMEDIATE * @see #TIMEOUT_IMMEDIATE
* @see #doExecute(Runnable) * @see #doExecute(Runnable)
*/ */
@Deprecated
@Override @Override
public void execute(Runnable task, long startTimeout) { public void execute(Runnable task, long startTimeout) {
Assert.notNull(task, "Runnable must not be null"); Assert.notNull(task, "Runnable must not be null");
@ -201,6 +203,7 @@ public class SimpleAsyncTaskExecutor extends CustomizableThreadCreator
} }
} }
@SuppressWarnings("deprecation")
@Override @Override
public Future<?> submit(Runnable task) { public Future<?> submit(Runnable task) {
FutureTask<Object> future = new FutureTask<>(task, null); FutureTask<Object> future = new FutureTask<>(task, null);
@ -208,6 +211,7 @@ public class SimpleAsyncTaskExecutor extends CustomizableThreadCreator
return future; return future;
} }
@SuppressWarnings("deprecation")
@Override @Override
public <T> Future<T> submit(Callable<T> task) { public <T> Future<T> submit(Callable<T> task) {
FutureTask<T> future = new FutureTask<>(task); FutureTask<T> future = new FutureTask<>(task);
@ -215,6 +219,7 @@ public class SimpleAsyncTaskExecutor extends CustomizableThreadCreator
return future; return future;
} }
@SuppressWarnings("deprecation")
@Override @Override
public ListenableFuture<?> submitListenable(Runnable task) { public ListenableFuture<?> submitListenable(Runnable task) {
ListenableFutureTask<Object> future = new ListenableFutureTask<>(task, null); ListenableFutureTask<Object> future = new ListenableFutureTask<>(task, null);
@ -222,6 +227,7 @@ public class SimpleAsyncTaskExecutor extends CustomizableThreadCreator
return future; return future;
} }
@SuppressWarnings("deprecation")
@Override @Override
public <T> ListenableFuture<T> submitListenable(Callable<T> task) { public <T> ListenableFuture<T> submitListenable(Callable<T> task) {
ListenableFutureTask<T> future = new ListenableFutureTask<>(task); ListenableFutureTask<T> future = new ListenableFutureTask<>(task);

3
spring-core/src/main/java/org/springframework/core/task/TaskRejectedException.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -25,7 +25,6 @@ import java.util.concurrent.RejectedExecutionException;
* @author Juergen Hoeller * @author Juergen Hoeller
* @since 2.0.1 * @since 2.0.1
* @see TaskExecutor#execute(Runnable) * @see TaskExecutor#execute(Runnable)
* @see TaskTimeoutException
*/ */
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class TaskRejectedException extends RejectedExecutionException { public class TaskRejectedException extends RejectedExecutionException {

5
spring-core/src/main/java/org/springframework/core/task/TaskTimeoutException.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -23,8 +23,9 @@ package org.springframework.core.task;
* @author Juergen Hoeller * @author Juergen Hoeller
* @since 2.0.3 * @since 2.0.3
* @see AsyncTaskExecutor#execute(Runnable, long) * @see AsyncTaskExecutor#execute(Runnable, long)
* @see TaskRejectedException * @deprecated as of 5.3.16 since the common executors do not support start timeouts
*/ */
@Deprecated
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class TaskTimeoutException extends TaskRejectedException { public class TaskTimeoutException extends TaskRejectedException {

3
spring-core/src/main/java/org/springframework/core/task/support/TaskExecutorAdapter.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -97,6 +97,7 @@ public class TaskExecutorAdapter implements AsyncListenableTaskExecutor {
} }
} }
@Deprecated
@Override @Override
public void execute(Runnable task, long startTimeout) { public void execute(Runnable task, long startTimeout) {
execute(task); execute(task);

6
spring-tx/src/main/java/org/springframework/jca/work/SimpleTaskWorkManager.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -31,7 +31,6 @@ import org.springframework.core.task.SimpleAsyncTaskExecutor;
import org.springframework.core.task.SyncTaskExecutor; import org.springframework.core.task.SyncTaskExecutor;
import org.springframework.core.task.TaskExecutor; import org.springframework.core.task.TaskExecutor;
import org.springframework.core.task.TaskRejectedException; import org.springframework.core.task.TaskRejectedException;
import org.springframework.core.task.TaskTimeoutException;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
import org.springframework.util.Assert; import org.springframework.util.Assert;
@ -143,6 +142,7 @@ public class SimpleTaskWorkManager implements WorkManager {
* (or -1 if not applicable or not known) * (or -1 if not applicable or not known)
* @throws WorkException if the TaskExecutor did not accept the Work * @throws WorkException if the TaskExecutor did not accept the Work
*/ */
@SuppressWarnings("deprecation")
protected long executeWork(TaskExecutor taskExecutor, Work work, long startTimeout, boolean blockUntilStarted, protected long executeWork(TaskExecutor taskExecutor, Work work, long startTimeout, boolean blockUntilStarted,
@Nullable ExecutionContext executionContext, @Nullable WorkListener workListener) throws WorkException { @Nullable ExecutionContext executionContext, @Nullable WorkListener workListener) throws WorkException {
@ -164,7 +164,7 @@ public class SimpleTaskWorkManager implements WorkManager {
taskExecutor.execute(workHandle); taskExecutor.execute(workHandle);
} }
} }
catch (TaskTimeoutException ex) { catch (org.springframework.core.task.TaskTimeoutException ex) {
WorkException wex = new WorkRejectedException("TaskExecutor rejected Work because of timeout: " + work, ex); WorkException wex = new WorkRejectedException("TaskExecutor rejected Work because of timeout: " + work, ex);
wex.setErrorCode(WorkException.START_TIMED_OUT); wex.setErrorCode(WorkException.START_TIMED_OUT);
workListenerToUse.workRejected(new WorkEvent(this, WorkEvent.WORK_REJECTED, work, wex)); workListenerToUse.workRejected(new WorkEvent(this, WorkEvent.WORK_REJECTED, work, wex));

12
spring-tx/src/main/java/org/springframework/jca/work/WorkManagerTaskExecutor.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -33,7 +33,6 @@ import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.task.AsyncListenableTaskExecutor; import org.springframework.core.task.AsyncListenableTaskExecutor;
import org.springframework.core.task.TaskDecorator; import org.springframework.core.task.TaskDecorator;
import org.springframework.core.task.TaskRejectedException; import org.springframework.core.task.TaskRejectedException;
import org.springframework.core.task.TaskTimeoutException;
import org.springframework.jca.context.BootstrapContextAware; import org.springframework.jca.context.BootstrapContextAware;
import org.springframework.jndi.JndiLocatorSupport; import org.springframework.jndi.JndiLocatorSupport;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
@ -218,11 +217,13 @@ public class WorkManagerTaskExecutor extends JndiLocatorSupport
// Implementation of the Spring SchedulingTaskExecutor interface // Implementation of the Spring SchedulingTaskExecutor interface
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
@SuppressWarnings("deprecation")
@Override @Override
public void execute(Runnable task) { public void execute(Runnable task) {
execute(task, TIMEOUT_INDEFINITE); execute(task, TIMEOUT_INDEFINITE);
} }
@Deprecated
@Override @Override
public void execute(Runnable task, long startTimeout) { public void execute(Runnable task, long startTimeout) {
Work work = new DelegatingWork(this.taskDecorator != null ? this.taskDecorator.decorate(task) : task); Work work = new DelegatingWork(this.taskDecorator != null ? this.taskDecorator.decorate(task) : task);
@ -254,7 +255,8 @@ public class WorkManagerTaskExecutor extends JndiLocatorSupport
} }
catch (WorkRejectedException ex) { catch (WorkRejectedException ex) {
if (WorkException.START_TIMED_OUT.equals(ex.getErrorCode())) { if (WorkException.START_TIMED_OUT.equals(ex.getErrorCode())) {
throw new TaskTimeoutException("JCA WorkManager rejected task because of timeout: " + task, ex); throw new org.springframework.core.task.TaskTimeoutException(
"JCA WorkManager rejected task because of timeout: " + task, ex);
} }
else { else {
throw new TaskRejectedException("JCA WorkManager rejected task: " + task, ex); throw new TaskRejectedException("JCA WorkManager rejected task: " + task, ex);
@ -265,6 +267,7 @@ public class WorkManagerTaskExecutor extends JndiLocatorSupport
} }
} }
@SuppressWarnings("deprecation")
@Override @Override
public Future<?> submit(Runnable task) { public Future<?> submit(Runnable task) {
FutureTask<Object> future = new FutureTask<>(task, null); FutureTask<Object> future = new FutureTask<>(task, null);
@ -272,6 +275,7 @@ public class WorkManagerTaskExecutor extends JndiLocatorSupport
return future; return future;
} }
@SuppressWarnings("deprecation")
@Override @Override
public <T> Future<T> submit(Callable<T> task) { public <T> Future<T> submit(Callable<T> task) {
FutureTask<T> future = new FutureTask<>(task); FutureTask<T> future = new FutureTask<>(task);
@ -279,6 +283,7 @@ public class WorkManagerTaskExecutor extends JndiLocatorSupport
return future; return future;
} }
@SuppressWarnings("deprecation")
@Override @Override
public ListenableFuture<?> submitListenable(Runnable task) { public ListenableFuture<?> submitListenable(Runnable task) {
ListenableFutureTask<Object> future = new ListenableFutureTask<>(task, null); ListenableFutureTask<Object> future = new ListenableFutureTask<>(task, null);
@ -286,6 +291,7 @@ public class WorkManagerTaskExecutor extends JndiLocatorSupport
return future; return future;
} }
@SuppressWarnings("deprecation")
@Override @Override
public <T> ListenableFuture<T> submitListenable(Callable<T> task) { public <T> ListenableFuture<T> submitListenable(Callable<T> task) {
ListenableFutureTask<T> future = new ListenableFutureTask<>(task); ListenableFutureTask<T> future = new ListenableFutureTask<>(task);

Loading…
Cancel
Save