Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Configuration
- public class YourConfig {
- @Bean
- public TaskScheduler scheduler() {
- return new ThreadPoolTaskScheduler();
- }
- // ...
- @Service
- public class YourTaskRunnable implements Runnable {
- @Autowired
- private TaskScheduler scheduler;
- @PostConstruct
- private void init() {
- ScheduledFuture future = this.scheduler.schedule(this, /* to execute immediately, for example */ Calendar.getInstance().getTime());
- // ...
- }
- @Override
- public void run() {
- // Your task code ...
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement