I have a @Scheduled method which runs without a problem when I build my Spring Boot application using embedded tomcat. But when i build my project in .war and deploy it using tomcat v8, it seem like scheduler not trigger. Other functions working great just this scheduler not trigger on my server.
@Component
public class DeleteUser {
@Autowired
private UserService userService;
@Autowired
private UserAuthoritiesService userAuthService;
private static final Logger logger = LoggerFactory.getLogger(DeleteUser.class);
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
//(cron="second, minute, hour, day of month, month, day(s) of week")
@Scheduled(cron="0 0 8 * * *", zone="Asia/Kuala_Lumpur")
public void schedulerDeleteUser() {
List<User> ls = userService.getAllInactiveUser3Day(new Date());
try {
if(ls.size()>0) {
for(User user: ls) {
userService.updateStatusAccount(false, user.getId());
}
}
}
catch(Exception e) {
logger.error(e.getMessage());
}
logger.info("Scheduler run at {}", dateFormat.format(new Date()));
}
}