001/*002 * Copyright 2002-2018 the original author or authors.003 *004 * Licensed under the Apache License, Version 2.0 (the "License");005 * you may not use this file except in compliance with the License.006 * You may obtain a copy of the License at007 *008 * https://www.apache.org/licenses/LICENSE-2.0009 *010 * Unless required by applicable law or agreed to in writing, software011 * distributed under the License is distributed on an "AS IS" BASIS,012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.013 * See the License for the specific language governing permissions and014 * limitations under the License.015 */016017package org.springframework.scheduling.commonj;018019import java.util.Date;020import java.util.concurrent.Delayed;021import java.util.concurrent.FutureTask;022import java.util.concurrent.ScheduledFuture;023import java.util.concurrent.TimeUnit;024025import commonj.timers.Timer;026import commonj.timers.TimerListener;027028import org.springframework.lang.Nullable;029import org.springframework.scheduling.TaskScheduler;030import org.springframework.scheduling.Trigger;031import org.springframework.scheduling.support.SimpleTriggerContext;032import org.springframework.scheduling.support.TaskUtils;033import org.springframework.util.Assert;034import org.springframework.util.ErrorHandler;035036/**037 * Implementation of Spring's {@link TaskScheduler} interface, wrapping038 * a CommonJ {@link commonj.timers.TimerManager}.039 *040 * @author Juergen Hoeller041 * @author Mark Fisher042 * @since 3.0043 * @deprecated as of 5.1, in favor of EE 7's044 * {@link org.springframework.scheduling.concurrent.DefaultManagedTaskScheduler}045 */046@Deprecated047public class TimerManagerTaskScheduler extends TimerManagerAccessor implements TaskScheduler {048049 @Nullable050 private volatile ErrorHandler errorHandler;051052053 /**054 * Provide an {@link ErrorHandler} strategy.055 */056 public void setErrorHandler(ErrorHandler errorHandler) {057 this.errorHandler = errorHandler;058 }059060061 @Override062 @Nullable063 public ScheduledFuture<?> schedule(Runnable task, Trigger trigger) {064 return new ReschedulingTimerListener(errorHandlingTask(task, true), trigger).schedule();065 }066067 @Override068 public ScheduledFuture<?> schedule(Runnable task, Date startTime) {069 TimerScheduledFuture futureTask = new TimerScheduledFuture(errorHandlingTask(task, false));070 Timer timer = obtainTimerManager().schedule(futureTask, startTime);071 futureTask.setTimer(timer);072 return futureTask;073 }074075 @Override076 public ScheduledFuture<?> scheduleAtFixedRate(Runnable task, Date startTime, long period) {077 TimerScheduledFuture futureTask = new Timer