60 lines
1.7 KiB
Java
60 lines
1.7 KiB
Java
/*
|
|
* Copyright (C) 2021 the original author or authors.
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
package we.config;
|
|
|
|
import java.util.Date;
|
|
import java.util.concurrent.Executor;
|
|
import java.util.concurrent.Executors;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.scheduling.Trigger;
|
|
import org.springframework.scheduling.TriggerContext;
|
|
import org.springframework.scheduling.annotation.SchedulingConfigurer;
|
|
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
|
|
|
|
/**
|
|
* @author hongqiaowei
|
|
*/
|
|
|
|
public abstract class SchedConfig implements SchedulingConfigurer {
|
|
|
|
private int executors;
|
|
|
|
public void setExecutors(int es) {
|
|
executors = es;
|
|
}
|
|
|
|
@Override
|
|
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
|
|
taskRegistrar.setScheduler(taskScheduler());
|
|
taskRegistrar.addTriggerTask(new Runnable() {
|
|
public void run() {
|
|
}
|
|
}, new Trigger() {
|
|
@Override
|
|
public Date nextExecutionTime(TriggerContext triggerContext) {
|
|
return null;
|
|
}
|
|
});
|
|
}
|
|
|
|
@Bean(destroyMethod = "shutdown")
|
|
public Executor taskScheduler() {
|
|
return Executors.newScheduledThreadPool(executors);
|
|
}
|
|
}
|