blob: cdd9a2cd0169b042cff49c81993780b468f3ed02 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
/**
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
* Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
*/
package org.onap.aai.cacher.service.tasks;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import org.onap.aai.cacher.service.helper.CacheHelperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.scheduling.config.IntervalTask;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import java.util.Date;
@Configuration
public class ScheduledTaskConfig {
private static final EELFLogger EELF_LOGGER = EELFManager.getInstance().getLogger(ScheduledTaskConfig.class);
private static final int THREAD_POOL_SIZE = 10;
private static final String THREAD_POOL_PREFIX = "poolScheduler";
private static final int TASK_INTERVAL_TIME = 30000;
private static final int TASK_DELAY_TIME = 0;
private ScheduledTaskConfig(){}
@Configuration
static class RegisterTaskSchedulerViaSchedulingConfigurer implements SchedulingConfigurer {
@Autowired
protected CacheHelperService chs;
@Override
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
taskRegistrar.setTaskScheduler(poolScheduler());
taskRegistrar.addFixedRateTask(new IntervalTask(() -> {
EELF_LOGGER.info(
"Job @ fixed rate " + new Date() + ", Thread name is " + Thread.currentThread().getName());
chs.checkAndInitTasks();
}, TASK_INTERVAL_TIME, TASK_DELAY_TIME));
}
@Bean
public TaskScheduler poolScheduler() {
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
scheduler.setThreadNamePrefix(THREAD_POOL_PREFIX);
scheduler.setPoolSize(THREAD_POOL_SIZE);
return scheduler;
}
}
}
|